Input/output redirection and pipelines for Linux operations

Source: Internet
Author: User
Article title: Linux operation-based input/output redirection and pipelines. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
In Unix, standard input stdin and standard output stdout are used to represent the input and output of each command, and stderr is used to output error messages. By default, these three standard input/output systems are associated with control terminal devices. Therefore, under standard conditions, each command usually obtains input from its control terminal and prints the output to the screen of the control terminal.

However, you can also redefine the input stdin and output stdout of the program and redirect them. The most basic usage is to redefine them to a file, get the input from a file, and output it to another file.

$ Ls> ls. out

$ Cat <ls. out

This type of input/output redirection provides great flexibility. you can record the output results or prepare the input and use files required by the program in advance, in this way, you do not need to re-input the code for multiple executions.

$ Echo "today is"> out

$ Date> out

Use> Mark to add the output result, and append the result to the output file, instead of simply overwriting the original file.

A more flexible way is to associate input and output with an execution command, rather than a fixed file.

$ Ls-l | grep mbox
The preceding command uses the ls-l input as the grep input, which is called a pipeline. Unix provides many powerful functions and small commands, but these commands are combined using pipelines to form a very powerful tool combination, which can complete very complex work.

Unix provides some special device files, which are used in some special cases. For example, if a special device file is/dev/null, the file cannot be fully written, and the written content is immediately discarded by the system. If you do not want to see the program output, you can use it for output.

$ Make world>/dev/null
Remove the screen output to make the entire program execution process very calm.

Related Article

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.