In general, you can think of each UNIX command (ls, cd, and so on) as an individual program that UNIX executes. For example, if you type ls /etc at thew prompt, UNIX will run the ls program on the /etc directory. Each program requires input (in this example, the contents of a directory or any other information that the program processed) and produces output (i.e., the displayed results).
Frequently, you'll want to run programs in sequence. For example, you could tell UNIX to read your resume and then spell-check it. In doing this, you connect two commands together and have them run in sequence. This process, in which you connect the output of one program to the input of another, is called piping. Depending on what you want to do, you can pipe together as many commands as you want—with the output of each acting as the input of the next.
As Figure 1.6 shows, you pipe commands together using the pipe symbol, which is the | character. In the following example, we'll pipe the output of the ls command (which lists the contents of a directory) to the more command (which lets you read results one screen at a time). For details about more, see Viewing file contents with more of this chapter.
To pipe commands:
ls | more
Tip
If you want to pipe more than two commands, you can. Just keep adding the commands (with a pipe symbol for each) in the order you want them executed.
Tip
Remember that the output of each command is piped to the next command. So a piped command, such as ls | spell | sort, could list files within a directory, then spell-check the list, then sort the misspelled words and display them onscreen. The correctly spelled file names would not appear.
Tip
Venture to Chapter 15 to find out more about running a spell-checker and Chapter 6 to find out more about sorting.
3.133.124.145