Redirect `stderr` to `stdout` for Unified Logging

Quick Tip

Redirect `stderr` to `stdout` for Unified Logging

Challenge: When running complex commands or scripts, error messages (stderr) and standard output (stdout) can appear in separate streams, making it difficult to capture all relevant information in a single log file or pipe it consistently to another command.

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

your_command_here 2>&1 | tee output.log

Why it works: File descriptor `2` represents `stderr`, and `&1` means “the same place as file descriptor `1` (stdout)”. By redirecting `2>&1`, you are sending all error messages to the same location as standard output, allowing `tee` or other redirection to capture both.

Pro-Tip: For simple redirection to a file, you can omit `tee` and just use `your_command_here > output.log 2>&1`.

Linux Tips & Tricks | © ngelinux.com | 5/18/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments