One, multi-command collaboration
In Linux systems, most commands are simple, with few complex commands, and each command often implements only one or more simple functions. You can implement a complex function by using a combination of commands from different functions.
The return data for almost all commands in Linux is plain text (because each command runs under the CLI), and data in plain text is the input format for most commands, which makes multi-command collaboration possible.
The Linux command line provides a pipeline and redirection mechanism, and multi-command collaboration is done through pipelines and redirects.
Second, the standard flow
For a terminal, it is possible to work with various types of data, int, float, double, char, string, or even a text file, and the terminal attaches more importance to the contents of the data itself, ignoring the type of the data and focusing on their content, abstracting them into a "stream" The concept of (Stream). The data flow is also generally called an I/O stream.
Almost every terminal has the I/O (input and output) of the data stream, generally, stream-based trends and uses have input streams, output streams, error streams, file streams, and so on, and generally, there are 3 default standard streams:
Name |
Description |
Number (File descriptor) |
Default Device |
Stdin |
Standard input stream |
0 |
Keyboard |
STDOUT |
Standard output stream |
1 |
Terminal |
STDERR |
Standard error Liu |
2 |
Terminal |
STDIN represents the standard input stream, which is usually the keyboard by default. STDOUT and STDERR, respectively, represent standard output streams and standard error streams, which are typically terminals by default.
Iii. Piping and redirection 1. redirect
Redirection can direct I/O streams (associations) to files rather than to the default terminal. Redirection is typically used to save the output or error information of a command to a specified file.
There are several common operators:
> redirect stdout to file (overwrite) >> redirect stdout to file (append) 2> redirect stderr to file (overwrite) 2>&1 REDIRECT StdErr and stdout to file (overwrite) < redirect stdin to File
2. Piping
Pipeline operations can implement the output of one command as input to another command. Pipelines are often used to combine different commands to achieve a complex function.
Operator:
| StdOut a command as a stdin of another command
Linux entry record: 16, Linux Multi-command collaboration: Pipeline and redirection