Redirect stderr and stdout in Bash
I want to redirect both stdout and stderr of a process to a single file. How do I do that in Bash?
Take a look here. Should be:
yourcommand &>filename
(redirects both stdout
and stderr
to filename).
do_something 2>&1 | tee -a some_file
这将把stderr重定向到标准输出和标准输出到some_file
并将其输出到标准输出。
You can redirect stderr to stdout and the stdout into a file:
some_command >file.log 2>&1
See http://tldp.org/LDP/abs/html/io-redirection.html
This format is preferred than the most popular &> format that only work in bash. In Bourne shell it could be interpreted as running the command in background. Also the format is more readable 2 (is STDERR) redirected to 1 (STDOUT).
EDIT: changed the order as pointed out in the comments
链接地址: http://www.djcxy.com/p/34726.html上一篇: 如何在提交表单时重定向