Separating Errors, and Discarding Output
Why standard error is separate. If errors went to standard output, then grep pattern file > results.txt would put error messages into your results file. Keeping them apart means the results file holds results and the errors still reach you on screen.
command 2> errors.txt captures only the errors.
command > out.txt 2> err.txt splits them into two files.
command > everything.txt 2>&1 merges error into output, which is what you want when you are saving a full transcript.
The bin that discards. /dev/null is a special file that throws away everything written to it. command 2> /dev/null runs the command and silences its errors, which is genuinely useful when a command reports things you do not care about, such as permission warnings while searching a large tree.
✦ Redirection is how a script leaves a record
The reason this matters beyond convenience is that a scheduled script has no screen to print to. Everything it learns has to be written somewhere or it is lost. Appending to a log file with a double arrow is how a script tells you what it did while you were not watching.
Mark this lesson complete
Signed in, your progress follows you to every device.