Home > OS >  In Linux redirection operator
In Linux redirection operator

Time:09-22

1.1 redirect redirect symbol

Output to a file or device to cover the original file
! Output to a file or device compulsory cover the original file
> Output to a file or device additional original file

2> A standard error output will be redirected to a file or device to cover the original file b - shell
2> Will be a standard error output redirected to a file or device is appended to the original file
2> & 1 will be a standard error output is redirected to standard output annotation: 1 is likely to be on behalf of the standard output
& A standard error output will be redirected to a file or device to cover the original file c - shell
| & amp; A standard error pipeline to another command as input

1.3 command guidance example

In bash command execution process, there are mainly three kinds of I/o, respectively is:
1. The standard input; The code is 0; Or stdin; Used for & lt;
2. The standard output: code for 1; Or called stdout; Use the way to 1 & gt;
3. The error output: the code is 2; Or stderr; Using the way of 2 & gt; [test @ test test] # ls - al & gt; List. TXT
Will show the results of the output to the list. The TXT file, if the file to exist to replace! [test @ test test] # ls - al & gt;> List. TXT
Will show the result of the accumulation to the list. The TXT file, the file for the accumulation of old data retention! [test @ test test] # ls - al 1 & gt; List. TXT 2 & gt; List. Err
Will display the data, the output of the right to the list. The TXT wrong data output to the list. The err [test @ test test] # ls - al 1 & gt; List. TXT 2 & gt; & 1
Will display the data, no matter right or wrong are output to the list. The TXT of! Error and correct file output to the same file, it must be above the method to write! Cannot write other format!

[test @ test test] # ls - al 1 & gt; List. TXT 2 & gt;/dev/null
Will display the data, the output of the right to the list. The TXT error data is to be discarded!/dev/null, to say the device as a black hole, is empty, not save,

1.4 why to use the command output oriented

? When the screen output information is very important, and we need to save time;
? In the implementation of the background program, don't want him to interfere with the normal output of the screen;
? Some systems of routine command (for example, is written in the/etc/crontab files) in the execution result, hope he can save;
? Some execute commands, we already know he may be the error message, so want to (2 & gt;/dev/null) will be when he lost;
? Error message and correct information to output, respectively: http://blog.csdn.net/songyang516/article/details/6758256
  • Related