How to redirect and append both stdout and stderr to a file with Bash?

前端 未结 7 1184
春和景丽
春和景丽 2020-11-22 01:16

To redirect stdout to a truncated file in Bash, I know to use:

cmd > file.txt

To redirect stdout in Bash, appending to

7条回答
  •  面向向阳花
    2020-11-22 01:42

    Try this

    You_command 1>output.log  2>&1
    

    Your usage of &>x.file does work in bash4. sorry for that : (

    Here comes some additional tips.

    0, 1, 2...9 are file descriptors in bash.

    0 stands for stdin, 1 stands for stdout, 2 stands for stderror. 3~9 is spare for any other temporary usage.

    Any file descriptor can be redirected to other file descriptor or file by using operator > or >>(append).

    Usage: <file_descriptor> > <filename | &file_descriptor>

    Please reference to http://www.tldp.org/LDP/abs/html/io-redirection.html

提交回复
热议问题