Pipes
Finally, the moment we've all been waiting for: pipes. These near-magical constructs are used so much in Linux/Bash that everyone should know about them. Anything more complex than a single command will almost always use pipes to get to the solution.
And now the big reveal: all a pipe really does is connect the stdout
of a command to the stdin
of another command.
Wait, what?!
Binding stdout to stdin
Yes, that is really all that happens. It might be a little disappointing, now that you know all about input and output redirection. However, just because the concept is simple, that doesn't mean that pipes are not extremely powerful and very widely used.
Let's look at an example that shows how we can replace input/output redirection with a pipe:
reader@ubuntu:/tmp$ echo 'Fly into the distance' > file reader@ubuntu:/tmp$ grep 'distance' < file Fly into the distance reader@ubuntu:/tmp$ echo 'Fly into the distance' | grep 'distance' Fly into the distance
For the normal redirection, we first...