Piping



next up previous contents index
Next: Combining I/O Redirection Up: Redirecting I/O and Previous: Redirection

Piping

Piping takes a command's output and transports it (pipes it) to the input of another command: 

% command1 | command2 Pipe command 1's output to 2's input.

Note that the | symbol is usually found on the far right side of the keyboard and sometimes has a small space in its middle. A common way to use piping is with the more command; this permits the examination of a command's output one screenful at a time. For example,

% grep FORMAT myprog.f | more Locate ``FORMAT,'' pipe finds to more.
% ls -l | more Pipe long list of files to more.

These commands cause the output of grep and ls to go to more, which then lists it one screenful at a time. Interestingly enough, while grep is finding the lines in myprog containing the word FORMAT, its output is feeding into more's input, and simultaneously more's output is going to its output-which in this case is your terminal-possibly before the original command has been completed.

Piping along a string of commands is also possible. For example,

% myprog | grep alpha | more 1 2 3.

Here the program myprog sends its output to grep, which in turn separates out all occurrences of the string alpha and then sends its output to more so we can view it on our terminal screen in less than a flash.



next up previous contents index
Next: Combining I/O Redirection Up: Redirecting I/O and Previous: Redirection