Linux learning series
- Install common software on Linux
- Linux command redirection /dev/null 2>&1 | output redirection
Common redirection
Where 0 represents keyboard input, 1 screen output and 2 error output. Redirect standard error to standard output and throw it below /dev/null
command >out.file 2>&1 &
Command >out.file redirects the output of the command to the out.file file, that is, the output is not printed to the screen but to the out.file file. 2>&1 redirects the standard error to standard output, where the standard output has been redirected to out.file, which also outputs the standard error to out.file. The final & is to make the command run in the background.
command > file 2>&1
First, command > file redirects standard output to file. 2>&1 is the standard error copying standard output, which is also redirected to file. The end result is that both standard output and error are redirected to file.
command 2>&1 >file
2>&1 Standard error The act of copying standard output while it is still at the terminal. >file the output is redirected to file, but the standard error remains on the terminal.
/dev/null 2>&1 This command redirects both standard output and error output to /dev/null, which means that any information generated is discarded.