Linux IO redirection

Source: Internet
Author: User

Linux IO redirection

By default, Linux commands obtain input from the standard input device (stdio) and output the result to the standard output device (stdout) for display. Generally, the standard input device is a keyboard. The standard output device is a terminal (Display ).

Generally, three files are opened when each command is run:

  • Standard input file (stdin): The file descriptor of stdin is 0. By default, linux programs read data from stdin.
  • Standard output file (stdout): The file descriptor of stdout is 1. The linux program outputs data in comparison to stdout.
  • Standard Error file (stderr): The file descriptor of stderr is 2. The linux program writes error messages to the stderr stream.

Output redirection

/Dev/null File
/Dev/null is a special file, and the content written into it will be discarded.

Example:

$ Date> date.txt convert the result of the datecommand to the file date.txt $ ll> date.txt then add the result of the llcommand to the file date.txt $ cat <date.txt then redirect the input of the catcommand to the file date.txt. (That is, the content of the file date.txt is used as the cat parameter) $ cat <date.txt> date2.txt redirects the content of the file date.txt to $ cat <EOF # prints the input string from the keyboard to the display until the input EOF $. /test 2> result.txt # redirects the error message of the script test to the file result $. /test> result.txt 2> & 1 export the error information and output information of the script test to the result.txt file.

This article permanently updates the link address:

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.