Quick Tip
The `2>&1` Magic: Unifying `stderr` and `stdout` for Cleaner Logs
Challenge: When running complex commands or scripts, `stdout` (standard output) and `stderr` (standard error) often get mixed up or appear in separate streams, making log analysis and debugging difficult.
The Solution: Redirect both `stderr` and `stdout` to a single location using the `2>&1` shell operator.
your_command_here 2>&1 | tee output.log
Why it works: File descriptor `1` represents `stdout`, and `2` represents `stderr`. By redirecting `2` to `1` (`2>&1`), you’re telling the shell to send `stderr` wherever `stdout` is currently going (in this case, piped to `tee`).
Pro-Tip: Use `tee` to also display the output on your terminal while saving it to a file. For instance, `your_command_here &> output.log` is a shorthand that achieves the same redirection to a file but won’t display it simultaneously on the terminal.
Linux Tips & Tricks | © ngelinux.com | 6/11/2026
