What Are stdin, stdout, and stderr?
Every command-line program has three standard I/O streams by default: stdin for input, stdout for normal output, and stderr for error messages — kept separat...
Published November 22, 2026
stdin, stdout and stderr are the three standard streams every Unix process gets: input (file descriptor 0), normal output (1) and error output (2). Redirection and pipes connect them between programs and files.
The concept
By default stdin is the keyboard and stdout/stderr go to the terminal. Programs write errors to stderr so they stay visible when stdout is redirected to a file.
Pipes (|) connect one program's stdout to the next program's stdin, which is the foundation of the Unix toolbox.
Three streams
0 stdin ◀ keyboard / pipe / file
1 stdout ▶ terminal / pipe / file
2 stderr ▶ terminal (errors)
Practical examples
Redirect output
ls > files.txt # stdout to file
ls missing 2> err.txt # stderr to file
ls . missing > all.txt 2>&1 # bothPipe
cat access.log | grep 404 | sort | uniq -c | sort -rn | headDiscard output
command > /dev/null 2>&1In code
process.stdout.write('data\n')
console.error('problem') // stderrCommon mistakes
- Redirecting only stdout and still seeing errors.
- Order mistakes: 2>&1 > file vs > file 2>&1.
- Printing errors to stdout in scripts.
Key takeaways
- 0 in, 1 out, 2 error.
- Pipes chain programs.
- Send errors to stderr.
FAQ
What is /dev/null?
A special file that discards anything written to it.
How do I append?
Use >> instead of >.