Quick Tip
Tame Your Logs: Unified stderr and stdout with `2>&1`
Challenge: When running commands, especially in scripts, you might encounter both standard output (stdout) and standard error (stderr) messages. These can get mixed up or be hard to manage, especially when trying to capture all output to a single log file.
The Solution: Redirect both stdout and stderr to the same destination using the `2>&1` redirection operator.
your_command_here &> output.log
Why it works: The `&>` is a shorthand that redirects both file descriptors 1 (stdout) and 2 (stderr) to the specified file. Alternatively, you can use `your_command_here > output.log 2>&1` which explicitly redirects stdout to `output.log` and then redirects stderr (file descriptor 2) to the same location as stdout (file descriptor 1).
Pro-Tip: Use `tee` to see output on screen and save it to a file simultaneously: `your_command_here 2>&1 | tee output.log`
Linux Tips & Tricks | © ngelinux.com | 6/28/2026
