Linux redirection
0, 1, and 2 represent standard input, standard output, and standard error message output, which can be used to specify the standard input or output that needs to be redirected.
In general use, the default is the standard output, both 1. When we need special use, we can use other labels. For example, output a program's error message to the log file:./program 2>log. The standard output is still on the screen, but the error message is output to the log file.
In addition, redirects can be implemented between 0,1,2. 2>&1: redirect error messages to standard output.
/dev/nullLinux also has a special file/dev/null, it is like a bottomless pit, all the information redirected to it will disappear into a trace. This is useful when we do not need to echo all of the program's information, so we can redirect the output to/dev/null.
If you want both the normal output and the error message to be displayed, redirect both the standard output and the standard error to/dev/null, for example:
# ls 1>/dev/null 2>/dev/null
Another approach is to redirect errors to standard output and then redirect to/dev/null, for example:
# ls >/dev/null 2>&1
Note: The order here cannot be changed, otherwise the desired effect is not achieved, the standard output is redirected to/dev/null, then the standard error is redirected to standard output, and the standard error is redirected to/dev/null because the standard output has been redirected to/dev/null , so everything was quiet:-)
Nohup combined
with /dev/null
Because of the use of nohup, the output is automatically written to the Nohup.out file, if the file is large, nohup.out will continue to grow, which we do not want to see, so you can use/dev/null to solve the problem.
Nohup./program >/dev/null 2>log &
If the error message is not wanted:
Nohup./program >/dev/null 2>&1 &
Linux boot background service nohup >/dev/null