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

 

One comment on “A Simple Trick for Grep

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Set your Twitter account name in your settings to use the TwitterBar Section.