| (Pipe): Communicates Between Processes


| (Pipe): Communicates Between Processes

Because pipes are integral to the functioning of a Linux system, they are introduced here for use in examples. Pipes are covered in detail beginning on page .

A process is the execution of a command by Linux (page ). Communication between processes is one of the hallmarks of both UNIX and Linux. A pipe (written as a vertical bar, |, on the command line and appearing as a solid or broken vertical line on keyboards) provides the simplest form of this kind of communication. Simply put, a pipe takes the output of one utility and sends that output as input to another utility. Using UNIX/Linux terminology, a pipe takes standard output of one process and redirects it to become standard input of another process. (For more information refer to "" on page .) Most of what a process displays on the screen is sent to standard output. If you do not redirect it, this output appears on the screen. Using a pipe, you can redirect the output so that it becomes instead standard input of another utility. For example, a utility such as head can take its input from a file whose name you specify on the command line following the word head, or it can take its input from standard input. Thus, you can give the command shown in on page as follows:

$ cat months | head
Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct

The next command displays the number of files in a directory. The wc (word count) utility with the w option displays the number of words in its standard input or in a file you specify on the command line:

$ ls | wc -w
14

You can use a pipe to send output of a program to the printer:

$ tail months | lpr