Linux stdout stderr
Linux stdout stderr
Standard out and standard error overview.
Understanding Output Streams
In Linux, every process has three standard streams:
- stdin (0): Standard input - where the program reads input from
- stdout (1): Standard output - where normal output goes
- stderr (2): Standard error - where error messages go
- Redirect regular output to a file while still seeing errors on screen
- Filter out error messages while capturing normal output
- Handle errors differently in scripts
- Pipe output through other commands without error messages interfering
Why Two Output Streams?
The separation of stdout and stderr allows you to:
Redirection Examples
Redirect stdout to a file:
command > output.txt
Redirect stderr to a file:
command 2> errors.txt
Redirect both to the same file:
command > all_output.txt 2>&1
Redirect stdout to file, stderr to another:
command > output.txt 2> errors.txt
Piping
Pipes (|) only pass stdout by default:
command1 | command2
To pipe both stdout and stderr:
command1 2>&1 | command2
Practical Applications
Understanding these streams is essential for: