Most Linux commands output to standard output after processing the data, but if the data goes through the series of steps to be processed, it is the number of data needed, which needs to be piped to help complete.
The pipe command uses the ' | ' As a delimiter, the execution result of the command before the qualifier is processed as input to the command after the delimiter. The execution mode here is not the same as the "Sequential Execution command". Pipeline commands not only emphasize the dependencies of the pre-and post-command, but also have a very important limitation:
the execution result of the pre-delimiter command must be output to standard output, and the command after the qualifier must be able to receive the standard input as the processing data .
Here are a few examples to familiarize yourself with the pipeline command:
- There are many files in the/etc directory, usually directly LS view, the screen can not display all, this is the use of Pipeline command:
ls -al /etc | less
The LS command outputs the file details from the directory to standard output, and less can accept standard input as processing data. This will reuse the ability to view the less command before and after, or even retrieve the ability to help us effectively view the required files.
- See how many recent users have logged in often using the last command, but will output very much information if you want to filter to view only users:
last | cut -d ‘ ‘ -f 1
Last the recent login information is output to the standard output, cut accepts the standard input as a parameter, processing, and then output to the standard output for display.
Core points of using pipeline commands
- The command before the pipe command can only handle the standard output, no processing capability for standard error output;
- The command after the pipeline command must be able to accept data from the previous command as standard input to continue processing;
The data from stdin must not be accepted by commands such as LS and CP. Tail, head, less, more and so on can accept the standard input.
Common commands in Linux pipe