A Simple Trick for Grep

grep is a great tool to search strings. I often use grep to check if a specific process is running or not. For example, we want to check if sshd is running, the command would be,

ps -ax |  grep sshd

In my computer, this gives the following output,

755 ?        Ss     0:00 /usr/sbin/sshd -D
6175 pts/1    S+     0:00 grep –color=auto sshd

The first line of output is what we want, but the second line is pesky. It is shown because of we’re using grep to search for sshd.

A simple trick is to use the invert command of grep. This is shown as below,

ps ax | grep -v grep | grep sshd

Now the output is,

755 ?        Ss     0:00 /usr/sbin/sshd -D