Tame Your Terminal: Unified Logging with `2>&1`
Quick Tip
Tame Your Terminal: Unified Logging with `2>&1`
Challenge: When running commands or scripts, you often want to capture both standard output (stdout) and standard error (stderr) into a single log file. By default, these go to separate streams, making unified logging a hassle.
The Solution: Redirect both stdout and stderr to a single file using the `2>&1` syntax.
your_command > output.log 2>&1
Why it works: File descriptor 1 represents stdout, and file descriptor 2 represents stderr. The `>` redirects stdout to `output.log`. Then, `2>&1` redirects file descriptor 2 (stderr) to the current location of file descriptor 1 (which is now `output.log`).
Pro-Tip: You can also use `&>` as a shorthand for `> … 2>&1` in Bash 4+ for a more concise redirection.
Linux Tips & Tricks | © ngelinux.com | 6/13/2026
