If you use cron job on Linux, some times you want to ignore the output of the command you executed. This can be done by adding “> /dev/null 2>&1” behind the cron job command.
The command is just work want it should be, but I always curious with what does 2>&1 means. The “> /dev/null” is pretty obvious of what it does without much more explanation, it just redirect all the output to /dev/null which in Linux means we don’t care with the output (or sort of, it’s my own definition).
I tried to search on Google about “2>&1” before, but got no luck, until today I read post at Xaprb post: What does “> /dev/null 2>&1? mean? Which give some explanation about it. Here is a summary of the post:
There are three standard sources of input and output for a program. Standard input usually comes from the keyboard if it’s an interactive program, or from another program if it’s processing the other program’s output. The program usually prints to standard output, and sometimes prints to standard error. These three file descriptors (you can think of them as “data pipes”) are often called STDIN, STDOUT, and STDERR.
Sometimes they’re not named, they’re numbered! The built-in numberings for them are 0, 1, and 2, in that order. By default, if you don’t name or number one explicitly, you’re talking about STDOUT.