Newcomers to Bash programming will sooner or later come across /dev/null and another obscure jargon: > /dev/null 2>&1 . It may look confusing but it’s fairly simple to understand and a fundamental part of shell programming. So let’s break it down with step-by-step examples.

To begin, /dev/null is a special file called the null device in Unix systems. Colloquially it is also called the bit-bucket or the blackhole because it immediately discards anything written to it and only returns an end-of-file EOF when read.

Let’s see what happens when we try writing to it with the file redirection operator ( > ).

# First let's try writing to this file.

$ echo 'text' > /dev/null # Upon inspection, we see that the write was successfully.

$ echo $?

0

The $? symbol is a special variable that always contains the exit status of the previous command; it will be overwritten every time you run a new command. By convention, an exit code of 0 indicates that the previous command was successful while anything greater indicates an error code for that specific program.