Unified Logging with `2>&1`
Quick Tip
Unified Logging with `2>&1`
Challenge: When troubleshooting or monitoring processes, you often need to capture both standard output (stdout) and standard error (stderr) into a single log file for a complete picture.
The Solution: Redirect both stdout and stderr to a single file using the `2>&1` redirection operator.
your_command > output.log 2>&1
Why it works: Standard output is file descriptor 1, and standard error is file descriptor 2. `2>&1` tells the shell to redirect file descriptor 2 (stderr) to wherever file descriptor 1 (stdout) is currently pointing. By placing `> output.log` before `2>&1`, stdout is already redirected to `output.log`, so stderr also goes there.
Pro-Tip: You can also use `&>` as a shorthand for `> … 2>&1` (e.g., `your_command &> output.log`).
Linux Tips & Tricks | © ngelinux.com | 5/2/2026
