Data flow redirection knowledge for Linux

Source: Internet
Author: User

One, what is data flow redirection

Before you say data flow redirection, let's say the concept of data flow. The data flow is divided into three types: standard input (stdin), standard output (stdout), and standard error output (stderr).

In simple terms, standard output refers to the correct information that the command executes, and the standard error output refers to the error message that is returned after the command execution fails. This information is printed on the screen by default.

So what happens when data flow redirects? The literal understanding is to change the flow of data to the specified file or device. For example, the correct information that is returned by executing the command (standard output information) flows to a file, the error message (standard error output) is then streamed to another file and the information of the two files is saved, and no information returned by the command execution is displayed on the screen.

Implementation of data stream redirection

1, data flow rewrite to the classification

Using the shell to implement data flow redirection in Linux is very simple, and here are 3 types of data flow redirects.

1 standard input (stdin): code 0, using < or <<

2 standard output (STDOUT): Code 1, using > or >>

3 standard error Output (STDERR): Code 2, using 2> or 2>>

See here, you may still be very puzzled, what is the function of the code,< and << What is the difference between,> and >>?

2, the role of the Code

The code is set to differentiate between different streams of data used in the command, for example, the 0 code is standard input. Note that by default,> and >> represent 1> and 1>> respectively, while < and << represent 0< and 0<< respectively.

3, standard output data flow redirect Detailed

Before I say the input, let me tell you the output, the general use of examples can make it easier for people to understand how the use of things. So take a look at the example below, in the current directory, there is already a text piece named StreamTest.txt, I use the cat command to test, we know, the cat command will output the contents of the text file to the screen. Take a look at the following example:

This paper url:http://www.bianceng.cn/os/linux/201410/45627.htm

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.