Standard error (stderr) is the stream to which a program writes diagnostic, error, and progress messages. It corresponds to file descriptor 2. Its purpose is to keep error output separate from normal data on stdout, so that pipelines and redirections do not inadvertently pollute the data stream with human-readable diagnostics.
By default, stderr is connected to the terminal, just like stdout. When you pipe or redirect a command, only stdout moves—stderr still appears on the terminal unless explicitly handled:
find / -name "*.conf" > found.txt # errors still on terminal
find / -name "*.conf" 2> /dev/null # discard errors
find / -name "*.conf" > found.txt 2>&1 # merge into file
Well-behaved programs distinguish between the two. make prints warnings and errors to stderr and normal progress to stdout; wget prints the progress bar to stderr so it does not contaminate the downloaded data on stdout. When writing scripts, use echo "warning: foo" >&2 to print to stderr, which is the convention for messages that should not be captured by pipelines.
Related terms: stdin, stdout, File Descriptor, Redirection
Discussed in:
- Chapter 7: Pipes, Redirection, and Streams — The Three Standard Streams
Also defined in: Textbook of Linux