Linux Data redirection

Source: Internet
Author: User


Number

0 standard input (stdin)

1 standard output (stdout)

2 standard error (STDERR)


Data redirection:

When executing a command, some commands execute when the result of successful execution or the process at execution and the execution of the command fail to execute the error prompt output to the terminal

Standard output, standard error output message to Terminal (Terminal) by default

Data redirection is the data that is exported by default to the terminal and uploaded to other files or devices



Use the command > file stdout to redirect to a file


Redirect the date output to the file file if the file does not exist

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/76/4F/wKioL1ZO43HymgVmAACN1gM7cTI380.png "title=" Rhce7-classroom-2015-11-20-17-05-30.png "alt=" Wkiol1zo43hymgvmaacn1gm7cti380.png "/>


Overwrite the file if it exists

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/76/50/wKioL1ZO5dyD8h3rAAA71gaDgKU836.png "title=" Rhce7-classroom-2015-11-20-17-17-33.png "alt=" Wkiol1zo5dyd8h3raaa71gadgku836.png "/>


Use the command > > file to append to the current file without overwriting the original file

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/76/51/wKiom1ZO5xrgiKb0AABEPE9awCA885.png "title=" Rhce7-classroom-2015-11-20-17-23-59.png "alt=" Wkiom1zo5xrgikb0aabepe9awca885.png "/>


Note Redirection stdout can prevent the process output from appearing on the terminal but cannot prevent STDERR error message output on the terminal

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/76/52/wKiom1ZO6deifezjAABBOcJSpkI926.png "title=" Rhce7-classroom-2015-11-20-17-36-05.png "alt=" Wkiom1zo6deifezjaabbocjspki926.png "/>


Use the command 2> file stderr to redirect files

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/76/51/wKioL1ZO6tCDYkYJAABwBVg2P18729.png "title=" Rhce7-classroom-2015-11-20-17-36-32.png "alt=" Wkiol1zo6tcdykyjaabwbvg2p18729.png "/>


The command 2>> file indicates that the stderr is appended to the file

REDIRECT stdout stderr to/dev/null and discard it (just not shown)

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/76/51/wKioL1ZO696zdOL3AABFHYnm77Q766.png "title=" Rhce7-classroom-2015-11-20-17-43-58.png "alt=" Wkiol1zo696zdol3aabfhynm77q766.png "/>


REDIRECT StdOut stderr to the same file at the same time

    1. Command &> file

[[email protected] ~]$ find/etc-name passwd &> file

2. Command > file 2>&1

[Email protected] ~]$ find/etc-name passwd > File 2>&1

Be careful not to think the same. Redirecting to the same file at the same time may cause confusion in the data cross-write order

[Email protected] ~]$ find/etc-name passwd > file 2> file



Append stdout stderr to the same file at the same time

Command > > file 2>&1

[Email protected] ~]$ find/etc-name passwd >> file 2>&1





This article is from the Linux Learning Notes blog, so be sure to keep this source http://10516823.blog.51cto.com/10506823/1715205

Linux Data redirection

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.