linux-(16) Piping and redirection

Source: Internet
Author: User
Tags stdin

The command behavior of Linux we provide a pipeline and redirection mechanism that enables multi-command collaboration through pipelines and redirects.

The data flow of the command-line shell is defined in the following three ways:

Name Description Number Default
Stdin Standard input 0 Keyboard
STDOUT Standard output 1 Terminal
STDERR Standard error 2 Terminal

command to receive parameters or data via stdin, through stdout output or through stderr output errors, through pipeline and redirection to control the data flow of the CLI

If the output is redirected to/dev/null there will be no output (this is usually used to filter the error message in the results)


Redirect:

> redirect stdout to file (overwrite), example: echo "xxx" > outfile

>> redirect stdout to file (append), example: echo "xxx" >> outfile

2> redirect stderr to file (overwrite), example: LS nothere 2> errout

2>&1 combining stderr with stdout, example: LS nothere 2>&1 alloutput

< redirect stdin, example: grep xxx </etc/passwd


Pipeline:

| (A vertical bar): The stdout of one command (the previous command) as the stdin of another command (the latter command), example: Ls-l | grep xxx


Pipelines are often used to combine different commands to implement a complex function that redirects an output or error message that is typically used to hold a command, which can be used to record execution results or to save an error message to a specified file.

linux-(16) Piping and 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.