How to redirect both stdout and stderr to a file

sdmythos_gr picture sdmythos_gr · Sep 23, 2011 · Viewed 212.9k times · Source

I am running a bash script that creates a log file for the execution of the command

I use the following

Command1 >> log_file
Command2 >> log_file

This only sends the standard output and not the standard error which appears on the terminal.

Can I log both the stderr and stdout logged to a file?

Answer

Mat picture Mat · Sep 23, 2011

If you want to log to the same file:

command1 >> log_file 2>&1

If you want different files:

command1 >> log_file 2>> err_file