Glossary

/dev/null

/dev/null is the data sink of the Unix world. Writes to it succeed instantly and disappear; reads from it return end-of-file immediately. It is used to suppress unwanted output, to feed empty input to programs that insist on reading, and as a general "throw this away" marker in shell scripts.

command > /dev/null                  # discard stdout
command 2> /dev/null                 # discard stderr
command > /dev/null 2>&1             # discard both
command &> /dev/null                 # bash shorthand
: > /dev/null                         # no-op with discarded output

A common idiom is checking whether a command exists or succeeds without caring about its output:

if command -v jq > /dev/null; then ...; fi
grep -q pattern file                  # -q means "quiet", same effect

On most systems /dev/null has the permissions crw-rw-rw-, so everyone can read and write it. It is a character device, major 1 minor 3. Jokes about it being the fastest database ever built are inevitable; so is the occasional horror story of someone who mistyped a redirect and sent important data into it.

Related terms: /dev, Device File, Redirection, /dev/zero

Discussed in:

Also defined in: Textbook of Linux