Redirect `stderr` to `stdout` for Unified Logging
Quick Tip
Redirect `stderr` to `stdout` for Unified Logging
Challenge: When running commands or scripts, errors (stderr) and normal output (stdout) are often directed to separate streams. This can make it difficult to capture all output, especially for logging purposes or when piping to other commands.
The Solution: Use `2>&1` to redirect standard error to standard output.
your_command_here 2>&1 | tee logfile.txt
Why it works: File descriptor 2 represents standard error, and file descriptor 1 represents standard output. `2>&1` tells the shell to send everything that would normally go to file descriptor 2 to file descriptor 1. The `tee` command then captures this unified stream and writes it to `logfile.txt` while also displaying it on the terminal.
Pro-Tip: You can also use `&>` as a shorthand for `2>&1` if your shell supports it (e.g., Bash 4+). For example: your_command_here &> logfile.txt
Linux Tips & Tricks | © ngelinux.com | 5/15/2026
