Meaning of /dev/null 2>&1 in Crontab’s Cron Job
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.
Related Article
Sideblog 
- Mozilla Released Thunderbird 3 9 December 2009
The long waited open source email client Thunderbird 3 is now released! Upgrading from Thunderbird 2 to Thunderbird 3 is very easy and almost automatically. Once you finished installing version 3, you. […] - Microsoft Wireless Comfort Desktop 5000 Keyboard and Mouse 22 October 2009
The Microsoft Wireless Comfort Desktop 5000 has been designed to enhance your Windows 7 experience. You can easily access programs in the task bar with convenient hot keys. Applications in the taskbar. […] - WooFunction: 178 Amazing Web Design Icons 28 September 2009
The WooFunction Icon Set includes 178 amazing web-related icons in a sophisticated and glossy design style. All 178 icons are available as 32×32 pixel PNG files and we can assure you that they are in. […] - Moblin the Next Generation OS for Netbook 27 September 2009
Moblin is an open source project that supports Linux-based software platform and is optimized for the next generation of mobile devices including netbooks, mobile Internet devices (MIDs), in-vehicle i. […] - Twitterify Your Wordpress Blog Using P2 Theme 21 September 2009
Twitter is becoming more and more popular due to its requirement as micro blogging is not much, only 140 characters that even less than a text message limit which is 160 characters. Blogger that is no. […]

August 25th, 2009 - 00:07
i’m still confused! what does STDIN, STDOUT, and STDERR mean ? and what do they do ?
September 1st, 2009 - 17:52
Linux was bulit mainly with the C programming language.
In the C programming language a program has three data streams which can be handled separately :
0 means STDIN (STandarD INput) which is usually the keyboard;
1 means STDOUT (STandarD OUTput) which is the monitor;
2 means STDERR (STandarD ERRor) which is usually also the monitor by default.
A program e.g. X by default prints it’s output to STDOUT, to the monitor.
In the “X >/dev/null 2>&1″ statement, the first part “X >/dev/null” redirects X’s output from STDOUT to the /dev/null file which is something like a “bottomless hole” in Linux. What goes there never comes back.
But X’s STDERR isn’t redirected yet so X’s error messages will still be printed to the monitor.
The last part of the statement “2>&1″ redirects the STDERR (2) to STDIN (1) which is already redircted to /dev/null.
So none of them prints to the monitor any more.
(We have to add the “&” sign before the number 1 otherwise STDERR (2) would be redirected to a simple file called 1 in the same directory instead of STDOUT.)
January 25th, 2010 - 06:24
In this line , there is a mistake “The last part of the statement “2>&1? redirects the STDERR (2) to STDIN (1) which is already redircted to /dev/null.” It should be STDERR (2) to STDOUT (1).
Best Regards,
Kalin Mandaliev