Quick Tip
Redirecting `stderr` to `stdout` for Unified Logging
Challenge: When debugging shell scripts or monitoring processes, it’s common to have informational output on standard output (`stdout`) and error messages on standard error (`stderr`). This can make it difficult to capture and analyze all relevant information in a single log file.
The Solution: Use the `2>&1` redirection operator to send `stderr` to the same location as `stdout`.
your_command_here 2>&1 | tee output.log
Why it works: File descriptor `2` represents `stderr` and file descriptor `1` represents `stdout`. By redirecting `2` to `1` (`2>&1`), you ensure that any output sent to `stderr` is also sent to `stdout`. Piping this to `tee` then allows you to view the output on your terminal while simultaneously saving it to `output.log`.
Pro-Tip: To redirect only `stdout` to a file, use `>`: `your_command_here > output.log`. To redirect only `stderr` to a file, use `2>`: `your_command_here 2> error.log`.
Linux Tips & Tricks | © ngelinux.com | 5/2/2026
