Examples of using pipelines to connect commands

To pipe the output from one command into another command:

   who | wc -l

This command tells you how many users are currently logged in on the system: a lot!

The standard output from the who command - a list of all the users currently logged in on the system - is piped into the wc command as its standard input. Used with the -l option this command counts the numbers of lines in the standard input and displays the result on the standard output.

To connect several commands together:

   ps -aux|grep joe|sort +5 -6|less

The first command ps -aux outputs information about the processes currently running. This information becomes the input to the command grep joe which searches for any lines that contain the username "joe". The output from this command is then sorted on the sixth field of each line, with the output being displayed one screenful at a time using the less pager.

[Home] [Search] [Index]