Use/dev/null 2>&1 to do this. This command means that the standard output and error output are all redirected to/dev/null, that is, all the information that is generated is discarded.
Here's a look at the difference between command > File 2>file and command > File 2>&1 . The first command > file 2>file means to send the standard output information generated by the commands, and the error output information to file 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 . About the shell: >/dev/null 2>&1 Detailed
The shell can often be seen: >/dev/null 2>&1
The result of the command can be defined in the form of a%> output
Break down this combination: ">/dev/null 2>&1" is part five.
Where does the 1:> delegate redirect to, for example: echo "123" >/home/123.txt
2:/dev/null represents an empty device file
3:2> indicates stderr standard error
4:& means equal to, 2>&1, 2 output redirect equals 1
5:1 means stdout standard output, the system default is 1, so ">/dev/null" is equivalent to "1>/dev/null"
Therefore,>/dev/null 2>&1 can also be written as "1>/dev/null 2> &1"
Then the statement execution procedure for this article title is:
1>/dev/null: First of all, the standard output redirects to the empty device file, that is, do not output any information to the terminal, it is plainly not to display any information.
2>&1: The standard error output is then redirected to standard output because the standard error output is redirected to the empty device file because the standard output was previously redirected to an empty device file.