O'Reilly logo

Linux and Unix Shell Programming by David Tansley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

5.4. Pipes

The pipe command lets you take the output from one command and use it as input to another command. The pipe is represented by the bar (|) sign. The general format is:

command1 | command2 

where the ‘|’ is the pipe.

In the following example, a file listing is carried out on the current directory, and all files are displayed or would be if the pipe was not there. The shell sees the pipe, takes all the files and gives them to the command on the right of the pipe, so that in essence the pipe is doing exactly what its name implies: piping the information from one side to the other. In this case grep then searches through this output looking for the pattern quarter1.doc:

						$ ls | grep quarter1.doc 
quarter1.doc
					

Let’s see that example again ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required