Linux Data redirection

Source: Internet
Author: User

Preparatory work:

We must understand the output type of data redirection in the following 3 ways:

    • Standard input (stdin): code 0, using < (replacing the original data) or << (accumulating on the original data)

    • Standard output (STDOUT): Code 1, using > (replacing the original data) or >> (accumulating on the original data)

    • standard error Output (STDERR): Code 2, using 2> (replacing the original data) or 2>> (accumulating on the original data )




Here are a few examples of how data redirection functions and uses

    1. The standard output and the standard error output will separate them in separate files.

      #:find/home-name. BASHRC > List_right 2>list_error

      --depending on the execution of the above command, no information will be displayed on the screen, and you need to view the command after it has been executed in the List_right and list_error two files.

    2. Display the correct execution information, do not keep the error message,/dev/null black hole Trash can store a variety of guidance information



#find/home-name. BASHRC 2>/dev/null

--depending on the execution of the above command, the screen will display only the correct execution information, and the error execution information will discard

3. save standard output and standard error output information in the same file

#find/home-name. BASHRC >list 2>&1

#find/home-name. BASHRC &>list

-based on the execution of the above command, we can view the standard output and standard error output information in the list file.


Standard input < or <<

Next we look at the case demo:

    1. To create a file with the cat command, we've been using the cat command to view the file, and then we'll look at the cat command combine > Orient to create the file

      #cat > Catfile

      >catfile Testing

      >cat file test

      > above using keyboard input data to create files, you can use Ctrl+d to leave

    2. Create the same file from another file

      #cat >catfile </etc/issue

      --We can check the information of these two files to see if the two files are the same size.

    3. End instantly with keyword input << keywords

      #cat > Catfile << "Out"

      >this is a out.

      >ok now stop

      >out---Enter the keyword immediately and ends without using ctrl+d to exit.




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.