Quick Tip
Tame Terminal Noise: 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, making analysis and troubleshooting much simpler.
The Solution: Redirecting stderr to stdout is a fundamental shell redirection technique.
your_command 2>&1 | tee output.log
Why it works: The `2>&1` part tells the shell to redirect file descriptor 2 (stderr) to file descriptor 1 (stdout). Then, `tee output.log` takes the combined output (which is now all on stdout) and both displays it on your terminal and writes it to `output.log`. If you only want to save to the file and not see it on the terminal, you can simply use `your_command 2>&1 > output.log`.
Pro-Tip: Use `&>` as a shorthand for `2>&1` on many modern shells (like Bash 4+ and Zsh) for cleaner redirection: `your_command &> output.log`
Linux Tips & Tricks | © ngelinux.com | 6/30/2026
