Unified Logging with `2>&1`
Quick Tip
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 for easier analysis, especially when debugging. By default, they are sent to separate streams.
The Solution: Redirect both stdout and stderr to a single destination using the `2>&1` construct.
your_command > output.log 2>&1
Why it works: File descriptor 1 (stdout) is redirected to `output.log`, and then file descriptor 2 (stderr) is redirected to where file descriptor 1 is currently pointing, effectively merging both streams into the same file.
Pro-Tip: For simply appending to the log file instead of overwriting, use `>>` instead of `>`: your_command >> output.log 2>&1
Linux Tips & Tricks | © ngelinux.com | 6/22/2026
