Example
Ls-L> out. File 2> & 1 &
Explanation:
Ls-L> out. File // redirects ls output to file out. File
2> & 1 // in shell, the file descriptor is usually stdin, stdout, stderr, I .e., 0, 1, 2. It can be seen that it uses LS-L> out. the error message generated by file in the output process is also stored in stdout, namely: 1. You can perform an experiment. If the command produces an error, the error message is in the out. file.
It may be a bit strange that & 1. Since> 2 on the Left can represent stderr, why cannot I use 1 directly on the right?
In fact, if you use 1 directly on the right side, you will find that the error message is not in out. file, but in file 1.
:~ $ Sudo./test1.sh P1 P2 P3 P4> out. File 2> 1 :~ $ LS1 out. File test1.sh :~ $ Cat 1 sudo:./test1.sh: Command not found :~ $ Cat out. File :~ $ Sudo./test1.sh P1 P2 P3 P4> out. File 2> & 1 :~ $ Cat 1 sudo:./test1.sh: Command not foundiie @ monitor :~ $ Cat out. File sudo:./test1.sh: Command not foundiie @ monitor :~ $
Because test1.sh does not have execution permission, the following error occurs: sudo:./test1.sh: Command not found.
The last &, needless to say, is to run in the background.
Reference: http://www.linuxsir.org/bbs/thread40501.html