Glossary

stdout

Standard output (stdout) is the default stream to which a program writes its normal output. It corresponds to file descriptor 1. By convention it carries the "successful" output of a command—the thing you would want to save or feed into the next stage of a pipeline. Error messages go to stderr instead, precisely so that stdout remains clean data.

ls > files.txt              # redirect stdout to a file
echo hello | wc -c          # pipe stdout to next command
curl -s https://example.com | grep title

Separating stdout from stderr is one of Unix's foundational design choices. It allows you to capture a program's data while still seeing its diagnostic messages on the terminal:

command > out.txt            # data in out.txt, errors still printed
command 2> err.txt           # data still printed, errors in err.txt
command > out.txt 2>&1       # merge: both in out.txt
command &> out.txt           # bash shorthand for the above

The order matters: 2>&1 > out.txt does not merge them into the file, because 2>&1 happens before > redirects fd 1. This rule—redirections are processed left to right—catches many people out.

Related terms: stdin, stderr, File Descriptor, Pipe, Redirection

Discussed in:

Also defined in: Textbook of Linux