Redirect stderr and stdout in Bash [duplicate] Redirect stderr and stdout in Bash [duplicate] shell shell

Redirect stderr and stdout in Bash [duplicate]


Take a look here. It should be:

yourcommand &> filename

It redirects both standard output and standard error to file filename.


do_something 2>&1 | tee -a some_file

This is going to redirect standard error to standard output and standard output to some_file and print it to standard output.


You can redirect stderr to stdout and the stdout into a file:

some_command >file.log 2>&1

See Chapter 20. I/O Redirection

This format is preferred over the most popular &> format that only works in Bash. In Bourne shell it could be interpreted as running the command in background. Also the format is more readable - 2 (is standard error) redirected to 1 (standard output).