Understanding Pipelines
A pipe will take the output of one command and use it as the input for another command. It’s represented by the |
symbol, which is on the same key as the backslash. You’ll often invoke a simple pipeline from the command-line for various purposes. But, you can also create very complex, multi-stage pipelines for your shell scripts.
Figure 3.1: Creating a pipeline. Note that stdout is short for Standard Output, and stdin is short for Standard Input.
To see how this can be useful, let’s say that you want to look at a listing of all files in a certain directory. But, there are so many files that the output would scroll off of the screen where you’d never be able to see it. You can solve the problem by taking the output of the ls
command and using it as the input for the less
command. It would look something like this:
[donnie@fedora ~]$ ls -l | less
The ls -l
listing will open in the less
pager, so that you can scroll...