Using a pipe
The output from one command can be piped in as input to the next command. Two or more commands linked by a pipe (|) are called a pipeline. A pipeline is written as:
You enter the commands on the same line and separate them by the "or-bar" character
command | command | ...
Many commands are well suited to being used in a pipeline. For example, the grep command searches for a particular string in input from a file or standard input (the keyboard). A command such as:
displays all the cp commands recorded among the 16 most recently recorded commands in your history file. The command:
history | grep "cp"
uses ls to obtain information about the contents of the working directory and uses grep to search through this information and display only the lines that contain the string
ls –l | grep "Jan"
Jan. The pipeline displays the files that were last changed in January.
A filter is a command that can read from standard input and write to standard output. A filter is often used within a pipeline. In the following example, grep is the filter:
lists all your processes that are currently active in the system and pipes the output to grep, which searches for every instance of the string cc. The output from grep is then piped to wc, which counts every line in which the string cc occurs and sends the number of lines to standard output.
ps -e | grep cc | wc -l