Frequently Asked Question

How do I redirect standard error?

Because standard error has file descriptor 2, you put the digit 2 immediately before the redirection operator. 2> errors.txt sends only stderr to the file and leaves stdout going wherever it would normally go (usually the terminal). 2>> errors.txt appends instead of truncating, which is what you want for long-running scripts that accumulate diagnostics.

A typical use is the find idiom find / -name "*.conf" 2>/dev/null. The command searches the whole filesystem, prints matching paths to stdout, and silently discards the inevitable "Permission denied" messages that come from directories your user can't read. Without that redirect the terminal would scroll with complaints faster than you could read the answers. Note there is no space between 2 and >, 2 > errors.txt would be interpreted as "run a command with argument 2, then redirect stdout".

Further reading and video