Symbol explanation for shell output input stream

Source: Internet
Author: User

> Append

> Overwrite

> & Set the previous storage location to the next storage location

P.S.: Of course, there is still an inverse <& meaning that the direction is different. If the append is changed to the forward append, this will not be re-written.

0 standard input

1 standard output

2 standard errors

 

Example:

 

ls /usr/tmp 2> err.file

Write the error generated by the command to the err. file. If the error does not exist, it is created. If the error exists, it is overwritten.

ls /usr/tmp &> output.file

Write both the error and output information to the err. file, create the file if it does not exist, and overwrite the file if it exists.

command 2>&1

Output the standard error information to the same location of the standard output. commadn represents any command. This is actually nonsense. addition is no different from directly running the command, because the location of the standard output is the output on the screen, the standard error message outputs the standard output position, that is, the screen, without any changes, because the standard error and the standard output information are originally the same output on the screen. or how do we operate linux?

 

command >output_file 2>&1

This command is a bit interesting. command also represents any command, you can use the ls display directory, or an error command like lsdflsl. Of course, you can enter the correct command to get the standard output information is returned for the command with incorrect input. Well, the first half of the command indicates that the command result is entered into the output_file file. If if this command is not created, it is overwritten if it exists, and of course the result of this command may be correct or wrong, but it remains unchanged, that is, if the standard output information is used information is put into the output_file file, so when you enter a correct command such as ls, you certainly write the standard output command into output_file. If you enter an incorrect command such as lsdfsf, standard output of course, the command will not write any information in output_file, but because of the following sentence, 2> & 1, it means that the standard error information will be written to the same location of the standard output information, therefore, even if the standard output does not have any information to write, the standard error will still write any error information to output_file, so this command and ll &> output. file actually means the same,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.