Friday, August 03, 2007

What does “> /dev/null 2>&1″ mean?

(Original artical can be found:

Example command:

cmd > file 2>&1

Output redirection

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 are often called STDIN(0), STDOUT(1), and STDERR(2), and use 0,1,2 to represent correspondingly.

by default, it looks like

Given that context, you can see the command above is redirecting standard output into file,  then redirecting standard error into standard output (you have to put an & in front of the destination when you do this). It looks like 

if the commnd is cmd <>&1, the it looks like 

No comments: