32MB.CN

Linux - Redirect all output to file
All POSIX operating systems have 3 streams: stdin, stdout...
扫描右侧二维码阅读全文
16
2015/08

Linux - Redirect all output to file

All POSIX operating systems have 3 streams: stdin, stdout, and stderr. stdin is the input, which can accept the stdout or stderr. stdout is the primary output, which is redirected with >, >>, or |. stderr is the error output, which is handled separately so that any exceptions do not get passed to a command or written to a file that it might break; normally, this is sent to a log of some kind, or dumped directly, even when the stdout is redirected. To redirect both to the same place, use:

command &> /some/file

EDIT: thanks to Zack for pointing out that the above solution is not portable--use instead:

*command* > file 2>&1 

If you want to silence the error, do:

*command* 2> /dev/null
Last modification:August 16th, 2015 at 05:05 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment