Linux Linux redirect redirect

Linux Redirection

 

Turn: http: //blog.csdn.net/songyang516/article/details/6758256

 

1 Redirect


1.1 redirection symbols

> output redirected to a file or a device covering the original document
>! Output is redirected to a file or device to force the original document cover
>> redirect the output to a file or the original file append device
<input redirection a program to 

1.2 standard error redirection symbol

2> the standard error output is redirected to a file or a device to cover the original document the shell-B
2 >> the standard error output is redirected to a file or a device is added to the original file
2> & 1 the standard error output is redirected to a standard output Notes: 1 probably represents the standard output
> & a standard error output is redirected to a file, or overwrite the original file device the shell-C
| & piped to a standard error command as input to another

1.3 redirecting exemplary command

during the command execution bash, there are three input and output conditions, namely:
1. the standard input; code is 0; or referred stdin; is used in a manner <
2 standard Output: code 1; or referred to stdout; 1 mode is used>
3. Error Output: code 2; or referred stderr; mode used is 2>


[test @test test] # ls -al > list.txt
output displayed to list.txt file, if the file exists to be substituted!


[test @test test] # ls -al >> list.txt
results will be displayed to the accumulation list.txt file, the file is cumulative, old data!


[test @test test] # ls -al 1> list.txt 2> list.err
output data to be displayed, the correct output to the error data to list.err list.txt


[test @test test] # ls -al 1> list.txt 2> & 1
data to be displayed, whether right or wrong are output to them list.txt! Error and correct file output to the same file, you must write to the above method! Other formats can not be written!

[test @test test] # ls -al 1> list.txt 2> / dev / null
data to be displayed, the correct output data to the error list.txt Discard! / dev / null, the device can be said to be a black hole. Is empty, that is not saved.

Why 1.4 To use the command output redirection

• When the information screen output is important, but we need him to put aside some time;
• the background of the program, do not want him to interfere with the normal output screen;
• Some system cases line commands (such as a file written in the / etc / crontab in) the results of hoping he can survive when;
• Some execute the command, we already know his possible error message, so I want to "2> / dev / null" he will lose;
• error message with the right message needs to separately output.

Turn: http: //blog.csdn.net/songyang516/article/details/6758256

 

1 Redirect


1.1 redirection symbols

> output redirected to a file or a device covering the original document
>! Output is redirected to a file or device to force the original document cover
>> redirect the output to a file or the original file append device
<input redirection a program to 

1.2 standard error redirection symbol

2> the standard error output is redirected to a file or a device to cover the original document the shell-B
2 >> the standard error output is redirected to a file or a device is added to the original file
2> & 1 the standard error output is redirected to a standard output Notes: 1 probably represents the standard output
> & a standard error output is redirected to a file, or overwrite the original file device the shell-C
| & piped to a standard error command as input to another

1.3 redirecting exemplary command

during the command execution bash, there are three input and output conditions, namely:
1. the standard input; code is 0; or referred stdin; is used in a manner <
2 standard Output: code 1; or referred to stdout; 1 mode is used>
3. Error Output: code 2; or referred stderr; mode used is 2>


[test @test test] # ls -al > list.txt
output displayed to list.txt file, if the file exists to be substituted!


[test @test test] # ls -al >> list.txt
results will be displayed to the accumulation list.txt file, the file is cumulative, old data!


[test @test test] # ls -al 1> list.txt 2> list.err
output data to be displayed, the correct output to the error data to list.err list.txt


[test @test test] # ls -al 1> list.txt 2> & 1
data to be displayed, whether right or wrong are output to them list.txt! Error and correct file output to the same file, you must write to the above method! Other formats can not be written!

[test @test test] # ls -al 1> list.txt 2> / dev / null
data to be displayed, the correct output data to the error list.txt Discard! / dev / null, the device can be said to be a black hole. Is empty, that is not saved.

Why 1.4 To use the command output redirection

• When the information screen output is important, but we need him to put aside some time;
• the background of the program, do not want him to interfere with the normal output screen;
• Some system cases line commands (such as a file written in the / etc / crontab in) the results of hoping he can survive when;
• Some execute the command, we already know his possible error message, so I want to "2> / dev / null" he will lose;
• error message with the right message needs to separately output.

Guess you like

Origin www.cnblogs.com/ptfe/p/10965580.html