Bash Redirect Output To File (stdout and stderr)

October 29, 2020
command > output.log 2>&1

Redirect both stdout and stderr to file.

command > output.log 2>&1

Redirect stdout and stderr to different file

command > output.log 2>error.log

Use >> for append instead of overwrite.

command >> output.log 2>&1

Without 2>&1 it will capture stdout only.

command > output.log

The folowing command also redirect both stdout and stderr to file, but it might not be well supported on all version and platform.

command &> output.log
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.