0: Indicates keyboard input (stdin)
1: Indicates standard output (stdout), system default is 1
2: Indicates error output (stderr)
Command >/dev/null 2>&1 & = = Command 1>/dev/null 2>&1 &
1) Command: Represents a shell command or an executable program
2);: indicates where to redirect
3)/dev/null: Empty device file representing Linux
4) 2: Indicates standard error output
5) &1:& denotes equivalent meaning, 2>&1, indicates 2 output redirect equals 1
6) &: Indicates background execution, that is, this instruction execution runs in the background
1>/dev/null: Indicates that standard output is redirected to an empty device file, which means no information is output to the terminal and no information is displayed.
2>&1: Indicates that the standard error output redirection is equivalent to standard output because the standard error output is also redirected to an empty provisioning document because the standard output was previously redirected to an empty device file .
This command means to execute the program in the background and redirect the error output 2 to standard output 1, and then put the standard output 1 all into the/dev/null file, which is empty.
So you can see ">/dev/null 2>&1" commonly used to avoid shell commands or programs, such as the content output in the run.
What is the difference between command > file 2>file and command > File 2>&1?
Command > File 2>file means that the standard output information generated by the command is sent to file with the wrong output information. Command > File 2>file StdOut and stderr are sent directly to file, file will be opened two times, so stdout and stderr will cover each other, so write quite use FD1 and FD2 two simultaneously to seize the file of the pipeline.
and command >file 2>&1 This order will stdout directly sent to file, stderr inherit the FD1 pipeline, and then sent to file, at this time, file was opened only once, also only used a pipeline FD1, It includes the contents of stdout and stderr.
From IO efficiency, the efficiency of the previous command is less efficient than the following command, so when writing a shell script, we use command > file 2>&1.
2>&1 >/dev/null
Command-line redirection is ready before executing the command . The explanation sequence is left to right, 2&>1, and 1 is the screen, so the standard error redirects to the screen, and 1>/dev/null, the standard output redirects to/dev/null, the 2>&1 >/dev/null above is not The same time either produces standard output or produces a standard error. It's a two different thing.
To explain it in the following variable way, it is obvious that these two ways are different, the former is like:
A=1
B=a
And the latter is like:
B=a
A=1
&>/dev/null
This is, whatever you are. File descriptor, all redirected to/dev/null
http://blog.csdn.net/reyleon/article/details/11595985
http://blog.csdn.net/web256/article/details/8244286
http://blog.csdn.net/sunrier/article/details/7695839
Linux ">/dev/null 2>&1 &"