Find the process you are looking for minus the grepped one

ps aux | grep [p]rocess-name
As an alternative to using an additional grep -v grep you can use a simple regular expression in the search pattern (first letter is something out of the single letter list ;-)) to drop the grep command itself.
Sample Output
> ps aux | grep [m]ingetty
root      2381  0.0  0.0   7152   824 tty1     Ss+  Aug11   0:00 /sbin/mingetty --noclear tty1
root      2382  0.0  0.0   7152   828 tty2     Ss+  Aug11   0:00 /sbin/mingetty tty2
root      2383  0.0  0.0   7156   828 tty3     Ss+  Aug11   0:00 /sbin/mingetty tty3
root      2384  0.0  0.0   7156   828 tty4     Ss+  Aug11   0:00 /sbin/mingetty tty4
root      2385  0.0  0.0   7156   832 tty5     Ss+  Aug11   0:00 /sbin/mingetty tty5
root      2410  0.0  0.0   7156   832 tty6     Ss+  Aug11   0:00 /sbin/mingetty tty6

By: olorin
2009-08-13 05:44:45

10 Alternatives + Submit Alt

What Others Think

Why does it work?
Weboide · 650 weeks and 1 day ago
I think I understand now, it's cause it appears exactly as "[p]rocess-name" in the process list.
Weboide · 650 weeks and 1 day ago
correctly :D
olorin · 650 weeks and 1 day ago
it works because "[p]rocess name" is really a regular expression which matches "process name" but not "grep [p]rocess name" because only grep interprets the [ and ] characters specially. The brackets form a character class:
bwoodacre · 650 weeks and 1 day ago
wicked, thanks for sharing this
masterofdisaster · 650 weeks ago
That was brilliant. Very cool.
Patola · 650 weeks ago
This is so helpful. I have been working on a script to capture memeory usage of a few processes that launch child processes at intervals. This helps clean up the logs I am capturing. Thanks!!! :-D
DaveQB · 650 weeks ago
PS how did you guys get a custom avatar?
DaveQB · 650 weeks ago
@DaveQB it's gravatar ( I had to go to my profile and re-save for it to work.
claytron · 650 weeks ago
why this not work on zsh? ps axu | grep [a]pache2 zsh: no matches found: [a]pache2 zsh --version zsh 4.3.17 (x86_64-unknown-linux-gnu)
hvnsweeting · 473 weeks and 1 day ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: