Redirect `stderr` to `stdout` for Unified Logging

Quick Tip

Redirect `stderr` to `stdout` for Unified Logging

Challenge: When running commands or scripts, you often have two streams of output: standard output (stdout) for normal messages and standard error (stderr) for error messages. Sometimes, you want to capture both into a single file for easier analysis.

The Solution: Use the `2>&1` redirection operator.

your_command_here 2>&1 | tee output.log

Why it works: `2` represents stderr and `1` represents stdout. `2>&1` redirects stderr to wherever stdout is currently going. When combined with `tee`, both streams are sent to the file `output.log` and also displayed on your terminal.

Pro-Tip: For simple redirection to a file without displaying on the terminal, you can omit `tee`: your_command_here 2>&1 > output.log

Linux Tips & Tricks | © ngelinux.com | 6/17/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted