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