Linux data redirection

Source: Internet
Author: User

Linux data redirection

Preparations:

We must understand the output types of data redirection in Linux. There are three types:

  • Standard input (stdin): the code is 0. Use <(replace the original data) or <(accumulate on the original data)

  • Standard output (stdout): the code is 1, use> (replace the original data) or> (accumulate on the original data)

  • Standard Error output (stderr): Code 2, Use 2> (replace the original data) or 2> (accumulate on the original data)

 

Below are some examples to demonstrate the functions and usage of data redirection.

  1. Standard output and standard error output are stored in different files.

    #: Find/home-name. bashrc> list_right 2> list_error

    -- Based on the execution of the preceding command, no information is displayed on the screen. You need to view the information after the command is executed in the list_right and list_error files.

  2. Display correct execution information, do not retain error information,/dev/null black hole waste bin can store various Guidance Information

 

# Find/home-name. bashrc 2>/dev/null

-- Based on the preceding command execution, only the correct execution information is displayed on the screen, and the incorrect execution information is discarded.

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

 

# Find/home-name. bashrc> list 2> & 1

# Find/home-name. bashrc &> list

-- According to the preceding command execution, we can view the standard output and standard error output information in the list file.

Standard Input <or <

Next we will look at the case Demonstration:

  1. Use the cat command to create a file. We have been using the cat command to view the file before. Next let's take a look at the cat command combined with> creating a file in a targeted way.

    # Cat> catfile

    > Catfile testing

    > Cat file test

    > If you create a file by entering data on the keyboard, press ctrl + d to exit.

  2. Use other files to create the same file

    # Cat> catfile </etc/issue

    -- We can query the information of these two files to see if the sizes of these two files are consistent.

  3. Use the <keyword to enter a data keyword and the result ends immediately.

    # Cat> catfile <"out"

    > This is a out.

    > OK now stop

    > Out --- the system ends immediately after the keyword is entered. You do not need to use ctrl + d to exit.

Redirection of input and output in Linux

Linux redirection: redirects stdout and stderr to a file.

Redirection of basic Linux commands

Pipelines and redirection in Linux

Linux Shell file redirection experience

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.