NEXT UP previous
Next: Background Jobs

Pipes

By writing the standard output from one program into a file and then feeding the contents of this file into the standard input of another command, you are effectively bolting the two commands together via the temporary file so that they work as one. This is such a common thing to want to do that Linux provides a facility, which the shell takes advantage of, to connect the two programs together directly without the need for, or use of, a temporary file. This facility is called a pipe.

A pipe uses the redirection operator. Rewriting the previous example to use a pipe gives:

	$ ls /usr/bin | wc -w
	     459

As Linux is a multi-tasking operating system, this command line (or pipeline as it is called) will be executed by running the two commands ls and wc concurrently, so that the output from ls can be read by wc as it is produced.

A pipeline is not just limited to two commands bolted together. Any number of commands can be joined together, with a pipe operator being used to connect each adjacent pair. With this arrangement, the output from the first command will become the input to the second. The output from the second becomes the input to the third, and so on.


NEXT UP previous
Next: Background Jobs