what does /dev/null 2>&1 command do ?
or
What does > /dev/null 2>&1″ mean?
I was running some CGI for disk formatting and during this process some warning messages were coming on screen; even though I was duplicating standard out file pointer to some temporary file pointer. It was not redirecting standard error messages to this temporary file. Searched on google, but was not able to hit google with right keyword. Got this answer of using /dev/null 2>&1.
Here is explanation,
In Linux There are three standard file descriptors, Standard In (STDIN, file descriptor 0), Standard Output (STDOUT, file descriptor 1) and Standard Error (STDERR, file descriptor 2). /dev/null is the null device, which is like "write only memory". > will write to the specified file (overwriting its contents) and >> will append to the specified file.
> /dev/null 2>&1 redirect both output and error to /dev/null
> /file 2>&1 redirect both output and error to /file
Explanation:
> redirects output to /dev/null
2>&1 redirect error to where > is redirected
So error also gets redirected to /dev/null
“> /dev/null” will redirect STDOUT to a BLACK HOLE
“2 > &1” will redirect STDERR to STDOUT which in turn is redirected to a BLACK HOLE
or
What does > /dev/null 2>&1″ mean?
I was running some CGI for disk formatting and during this process some warning messages were coming on screen; even though I was duplicating standard out file pointer to some temporary file pointer. It was not redirecting standard error messages to this temporary file. Searched on google, but was not able to hit google with right keyword. Got this answer of using /dev/null 2>&1.
Here is explanation,
In Linux There are three standard file descriptors, Standard In (STDIN, file descriptor 0), Standard Output (STDOUT, file descriptor 1) and Standard Error (STDERR, file descriptor 2). /dev/null is the null device, which is like "write only memory". > will write to the specified file (overwriting its contents) and >> will append to the specified file.
> /dev/null 2>&1 redirect both output and error to /dev/null
> /file 2>&1 redirect both output and error to /file
Explanation:
> redirects output to /dev/null
2>&1 redirect error to where > is redirected
So error also gets redirected to /dev/null
“> /dev/null” will redirect STDOUT to a BLACK HOLE
“2 > &1” will redirect STDERR to STDOUT which in turn is redirected to a BLACK HOLE
Comments