How to Use Grep Combined with Standard Output From Other Commands

Grep is often most powerful when examining the output of other shell commands. This example searches the Linux processes from the ps command for apache. Most sysadmins will use this technique at least once a week.

ps aux | grep apache

Example Output – all processes with the name apache in them

root 17489 0.0 0.0 384472 824 ? Ss Dec12 0:04 /usr/sbin/apache2 -k start
www-data 17499 0.0 0.1 463020 1060 ? S Dec12 0:02 /usr/sbin/apache2 -k start
www-data 17500 0.0 0.0 459500 852 ? S Dec12 0:00 /usr/sbin/apache2 -k start
www-data 17501 0.0 0.0 459436 832 ? S Dec12 0:06 /usr/sbin/apache2 -k start
www-data 17502 0.0 0.0 458924 828 ? S Dec12 0:03 /usr/sbin/apache2 -k start
www-data 17503 0.0 0.0 458920 836 ? S Dec12 0:02 /usr/sbin/apache2 -k start
root 25473 0.0 0.0 10460 936 pts/4 S+ 22:21 0:00 grep –color=auto apache