"If you're a novice shell user, you've probably heard of pipes
but don't really know what they are or how to use them. A pipe
is a special line of communication opened by the shell between one
program's output and another program's input. In the shell, a
pipe is represented by the vertical bar (|) character."
"To connect a command's output to another command's input using
a pipe, place a vertical bar between the two commands. For example,
to get a directory listing but send it to the printer instead of to
the display, try:
$ ls -1 | lpr
In this case, the output of the ls command goes to the the lpr
command, which uses it as input and sends it to the printer."
"Sometimes, very complex tasks can be performed by
connecting long strings of pipes together:
This series of commands first gets a list of files in the current
directory with ls. This list is sent to the grep command, which
searches for the text "txt" in the filenames. The list of filenames
containing the word "txt" is then sent to the grep command again,
this time to filter out any names containing the text "jake" from
the list. This shortened list is then sent to the cut command,
which removes all "extensions" from the filenames. The list is now
sent to sort, which rearranges the list into alphabetical order
before finally sending it to lpr which will send the list to the
Some of the products that appear on this site are from companies from which QuinStreet receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. QuinStreet does not include all companies or all types of products available in the marketplace.