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 different streams. This can make it difficult to capture all output in a single log file or analyze it efficiently.
The Solution: Use the `2>&1` redirection operator to merge standard error into standard output.
your_command 2>&1 | tee your_log_file.log
Why it works: `2` represents the file descriptor for standard error, `&` indicates that `1` is a file descriptor, and `1` represents standard output. This redirects all error messages to the same stream as the standard output, allowing `tee` to capture both.
Pro-Tip: You can also redirect only stderr to a file and keep stdout separate: your_command 2> error.log
Linux Tips & Tricks | © ngelinux.com | 6/18/2026
