Pipeline and redirection under Linux

Source: Internet
Author: User

Pipeline and redirection under Linux

    1. System default settings:

      Standard input: stdout,0

      Standard output: stdin,1

      Standard error Output: stderr,2

2.I/O Redirect:

: Overwrite output

SET-C: Disallow redirection of existing file overrides

To force overwrite output redirection: Use >|

Set +c: Enables redirection of file overrides that already exist

>>: Append output

2>: standard error output

2>>: Standard error Append method

&>: Standard or error output to the same file

Example Description: ls/etc/&>/tmp/err.txt

>filename 2>&1: As with the &> function, the output of standard or error to the same file

Example Description: ls/etc/>/tmp/err.txt 2>&1

<: Input redirection

<<eof:eof to the end, you can write the concluding character arbitrarily

To illustrate:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/7E/E1/wKioL1cLr9yS_MgtAAC4PyEIlq8987.jpg "title=" Eof.jpg "alt=" Wkiol1clr9ys_mgtaac4pyeilq8987.jpg "/>

3. Pipeline: The output of the previous command, as input to the latter command

Format: Command 1 | Command 2 | Command 3 | ...

Tee: Copies a copy saved to the specified file, and then prints one copy of the output to the screen

3.1. Example: Remove the user name and UID from the/etc/passwd file, and display in descending order of the UID number;

cut-d:-f1,3,/etc/passwd | SORT-T:-k2-n-R

3.2. Example: Remove the user name and UID of the 6th user in the/etc/passwd file and the shell, display it to the screen and save it to the/tmp/pw.txt file

Cut-d:-f1,3,7/etc/passwd | Tee/tmp/pw.txt

3.3. Example: Append alias COPY=CP line to the current user's. bashrc file without using a text editor

echo "Alias COPY=CP" >> ~/.BASHRC

This article is from the "Xavier Willow" blog, please be sure to keep this source http://willow.blog.51cto.com/6574604/1762757

Pipeline and redirection under 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.