Bash Redirect Output To File (stdout and stderr)

Sep 4, 2017
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

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.