Quick Tip
Tame Your Terminal: Unified Logging with `2>&1`
Challenge: When running commands or scripts, it’s common to have output split between standard output (stdout) and standard error (stderr). This makes it difficult to capture all relevant information in a single log file or to pipe it to another command.
The Solution: Use shell redirection to combine both stdout and stderr into one stream.
command &> logfile.txt # or equivalently command > logfile.txt 2>&1
Why it works: The `&>` operator redirects both stdout and stderr to the specified file. The `2>&1` syntax specifically redirects file descriptor 2 (stderr) to file descriptor 1 (stdout), effectively merging them.
Pro-Tip: For interactive sessions where you only want to capture stderr, you can redirect it to /dev/null: `command 2> /dev/null`
Linux Tips & Tricks | © ngelinux.com | 6/3/2026
