2>&1
17 Mar 2009
A common practice when adding entries to crontab is to end the entry like this:
>/dev/null 2>&1
The purpose of this is to suppress any output from the command itself, because we’re not interested. I picked up this syntax years ago because it just works, but I never knew what the 2>&1
actually meant, until today.
The first part:
>/dev/null
Means redirect STDOUT
(the standard output stream) to /dev/null
(which is basically a blackhole for bits). That’s easy enough.
The second part:
2>&1
Means redirect STDERR
(standard error stream) to the same place as STDOUT
(which was just specified). STDOUT
has the assigned number 1 and STDERR
has the assigned number 2.
This way both STDOUT
(1) and STDERR
(2) are directed to /dev/null
and all output of the cronned command is suppressed.