Learning of redirected output in Linux

  
        

Here, the redirection can be understood as follows:

The original output method is like a faucet that drains water into a pool (screen), and water is the content to be output

When the faucet is transferred to a bucket (file) that is not a pool, it is redirected.

The output methods in Linux are mainly:

Two ways of standard output:

STDOUT standard output

STDERR standard error

The output of the screen can be redirected so that the content that should have been output to the screen is redirected to other places,

For example: File:

Format: Command operation file name < Br>

egls /etc -l 1> ls.txt 2>err.txt

where:

The command is still the original command, all known output commands are is allowed.

The operation is the type of output, there are

1> one class, STDOUT

2> second class, STDERR

&> all (including Class 1 and Class 2 messages) Note that if there is an error message in the output at this time, it will be output first, regardless of whether the class 1 or class 2 output is executed first.

> If no number (type) is added, the default is Standard output, ie 1

The operation it performs is to first delete the file to be redirected,

Note this, whether it is append or append to temporary file. >

The file name is the location to be redirected to. If the file is already in the original path, it will be overwritten. If not, it will be generated.

If you want the content in the original file not to be overwritten but appended later (written in the back) then you can use the following operation

1>> with >>< Br>

2>>

&>>

If the output being redirected has standard output and standard error output when appending mode, then

eg ls /etc /wrongdir 1>>ls.txt 2>>err.txt

ls /etc /wrongdor 1>>ls.txt 2>>ls.txt

However, I have seen it in ubuntu12.04 and it is ok to use &>>.

When a certain type of output is redirected, the output of the class will not be displayed on the screen.

When both the standard output and the standard error output exist, the redirect is determined according to the type of operation. Content and redirected files.

head command: from the beginning

tail command: look at the tail

can be followed by parameters for processing:

e.g. cat 5.txt

Copyright © Windows knowledge All Rights Reserved