grep is very often used as a "filter" with other commands. It allows you to filter out useless information from the output of commands. To use grep as a filter, you must pipe the output of the command through grep. The symbol for pipe is "|".
The following example displays files ending in ".ps" that were created in the month of May:
$ ls -l *.ps | grep May |
The first part of this command line,
ls -l *.ps |
produces a list of files:
The second part,
| grep May |
pipes that list through grep, looking for the pattern May:
$ ls -l *.ps | grep May -rw-r--r-- 1 elvis 2356 May 22 12:56 clock.ps -rw-r--r-- 1 elvis 5644 May 22 15:07 buttons.ps $ |