UNIX Primer

Home | Primer Home


Piping is the term used to describe the creation of a connection between multiple programs using the vertical bar (pipe) operator. This is done to automatically send the output of one program into the input of another program. Note that not all programs support this type of interaction.

To make it clear to you what this does, it's best to try it out on your own. Try the following examples on your command line:

ls | more
echo "hello world" | less
who | cut -c1-8 | sort
w | grep "bash"

The first example runs 'ls' and sends its output through 'more', resulting in the ability to see the output of 'ls' a page at a time.

The second runs 'echo "hello world"' and sends its output through 'less'. This displays the string "hello world" in the 'less' viewer.

The third example shows the usernames of everyone logged on, in alphabetical order. This is accomplished by sending the output of 'who' through the 'cut' program, which in turn sends its output (the cut text) through 'sort', which puts it in order.

The final example shows the 'w' entries that contain the word "bash".

Notice that three new commands are introduced in the last two examples. 'Sort' lexigraphically sorts a list, 'cut' trims lines of text and 'grep' searches for a particular regular expression (see regular expressions for more details). These commands are described below for your reference.

Related Commands:

cut Cuts out a section of the given set of characters (a file, piped input, etc).
cut -c#-# <filename(s)>
  • With piping, very useful for isolating information.
  • See the manual file for 'paste' for the inverse operation.

grep Global Regular Expression Parser To find a particular expression inside of a given set of characters (a file, piped input, etc).
grep <reg_exp> <filename(s)>

sort To sort a set of data lexigraphically (a file, piped input, etc).
sort <filename(s)>

See Also:

Designed by D. Kaminsky
Edited by Diana Palsetia
© University of Pennsylvania, 2008