上QQ阅读APP看书,第一时间看更新
Pipes
Pipes are the last unidirectional communication method between processes. As the name suggests, pipes connect two ends – a process input with another process output – making it possible to process on the same host to communicate in order to exchange data.
These are classified as anonymous or named:
- Anonymous pipes link one process standard output to another process standard input. It can be easily done inside a shell with the | operator, linking the output of the command before the pipe as input for the one after the pipe. ls -l | grep "user" gets the output of the ls command and uses it as input for grep.
- Named pipes use a specific file in order to execute the redirect. The output can be redirected to a file with the > (greater) operator, while the < (less) sign allows you to use a file as input for another process. ls -l > file.txt saves the output of the command to a file. cat < file.txt sends the contents of the file to the command's standard input, and the standard input copies them to the standard output.
It is also possible to append content to a named pipe using the >> (double greater) operator, which will start writing from the end of the file.