Linux Getting Started Foundation--linux Multi-command collaboration: Pipeline and redirection

Source: Internet
Author: User
Tags stdin

Linux Multi-command collaboration: Pipelines and redirects don't reinvent the wheel. One of the core concepts of open source culture is not to reinvent the wheel, many of the open source software is a re-assembly of existing software, code, functions, as if through parts assembling machines, the development and sharing of source code makes this possible, At the same time, it also greatly provides efficiency and productivity.
Pipeline and redirection in Linux systems, most commands are simple, with few complex commands, and each command often implements only one or more simple functions that can be used to accomplish a complex function by combining commands of different functions. The technique for combining commands is pipeline and redirection.
In Linux, the return data for almost all commands is plain text (because the commands are run under the CLI), and the data in plain text is the input format for most commands, which makes multi-command collaboration possible.
The Linux command provides us with a pipeline and redirection mechanism, Multi-command collaboration is done through pipelines and redirects.
Pipelines and redirects
The command shell's data flow has the following definitions:
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, stdout output or output error via stderr
Pipelines and redirects
Through pipelines and redirects we can control the data flow of the CLI
classification keyword definition examples
REDIRECT > redirect standard output to file (overwrite) echo "Linux" > outfile
ls > outfile
>> redirect standard output to file (append) echo "Hello" >> outfile
Date >> outfile
2> redirect stderr to file ls nothere 2> errout
2>&1 combines stderr with stdout ls nothere 2>&1 allerrout
< redirect stdin grep Liu </etc/passwd
Pipeline | StdOut of one command as another ls-l | grep Google
Command StdIn (this can be done with multiple cat * | grep Hello
Command Collaboration) (Find all the lines in the document that contain hello)
Pipelines and redirects
pipelines are often used to combine different commands to achieve a complex function.
Redirection is typically used to save output or error information for a command, which can be used to record execution results or to save an error message to a specified file.


Linux Getting Started Foundation--linux Multi-command collaboration: Pipeline 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.