Hide grep command from ps output

Posted: 28th October 2014 by Tim in Linux
Tags: , , , ,

When searching for a running process on a *nix machine, it is common to use ps together with grep, like so:

ps -ef | grep vim

This works well enough for quick searches, but will always return the grep command since grep vim will always contain the string “vim”. The pgrep utility can work around this, but if that’s not available you can use this grep trick:

ps -ef | grep [v]im

Putting square brackets around one letter will still instruct grep to match “vim” in the ps output, but the grep command itself will not match since it does not contain this string exactly.