next up previous contents index
Next: Multitasking Up: The Standard Input and Previous: Input Redirection

Solution: The Pipe


Many Unix commands produce a large amount of information. For instance, it is not uncommon for a command like ls /usr/bin to produce more output than you can see on your screen. In order for you to be able to see all of the information that a command like ls /usr/bin, it's necessary to use another Unix command, called more .gif more will pause once every screenful of information. For instance, move < /etc/rc will display the file /etc/rc just like cat /etc/rc would, except that more will let you read it.gif

However, that doesn't help the problem that ls /usr/bin displays more information than you can see. more < ls /usr/bin won't work--input redirection only works with files, not commands! You could do this:


However, Unix supplies a much cleaner way of doing that. You can just use the command ls /usr/bin | more. The character ``|'' indicates a pipe. Like a water pipe, a Unix pipe controls flow. Instead of water, we're controlling the flow of information!

A useful tool with pipes are programs called filters . A filter is a program that reads the standard input, changes it in some way, and outputs to standard output. more is a filter--it reads the data that it gets from standard input and displays it to standard output one screen at a time, letting you read the file.

Other filters include the programs cat , sort , head , and tail . For instance, if you wanted to read only the first ten lines of the output from ls, you could use ls /usr/bin | head.


Converted on:
Mon Apr 1 08:59:56 EST 1996