Data redirection in Linux

Source: Internet
Author: User

Redirection refers to the output of data to other places, such as devices, files, and so on. That involves the question of where to send the data.

The origin and result of command execution in Linux, see:

Standard input and standard error are output to the screen, which makes the screen very confusing and too much of the output to read. Even sometimes the output content is very important to save, what should I do??

The answer is: data redirection, importing the output to a different location.

Special symbols for data redirection in Linux:

    • Standard input: Code 0, using < or <<
    • Standard output: Code 1, use 1> or 1>>, or you can use the default representation > or >>
    • Standard error Output: Code 2, using 2> or 2>>

The difference between > and >> is that the output content redirects to the destination differently:

To redirect in a way that overwrites the original data of the destination
>>: Re-oriented in an additional way

ls /etc > list

If the above will list the files in the ETC directory, write them to the list file.

    1. If the list file does not exist, create
    2. Clear List File contents
    3. Writes the standard output of LS to the list

If the list is not emptied, it is written in an appended way, using the >>

1. Only the right data is required

Using a/dev/null trash bin

#将find的结果中错误的输出丢弃,只显示正确的结果。避免错误数据的干扰find /home -name .bashrc 2> /dev/null
2. Output data that requires both correct output and bad demand
find /home -name .bashrc > list 2>&1find /home -name .bashrc &> list

Both standard output and standard error are written to list

3. Use of standard input < and <<

Since you are using <, you definitely need to enter the source. < file, you can enter the contents of the file as standard.

cat > back <~/.bashrc

The above uses both > and < (input and output redirection) to back up the. bashrc file.

cat > list

The above command will redirect the screen input (standard input) to the file list as output, and then use Ctrl+d to exit. But you can do the following:

cat > list << "eof"

This allows you to exit as long as "EOF" is entered on the screen. << represents end input.

Data redirection in Linux

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.