ps aux | grep [p]rocess-name

Find the process you are looking for minus the grepped one

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

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

9 Alternatives + Submit Alt

What Others Think

Why does it work?
Weboide · 457 weeks and 5 days ago
I think I understand now, it's cause it appears exactly as "[p]rocess-name" in the process list.
Weboide · 457 weeks and 5 days ago
correctly :D
olorin · 457 weeks and 5 days 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: http://www.regular-expressions.info/charclass.html
bwoodacre · 457 weeks and 4 days ago
wicked, thanks for sharing this
masterofdisaster · 457 weeks and 4 days ago
That was brilliant. Very cool.
Patola · 457 weeks and 4 days 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 · 457 weeks and 4 days ago
PS how did you guys get a custom avatar?
DaveQB · 457 weeks and 4 days ago
@DaveQB it's gravatar (gravatar.com). I had to go to my profile and re-save for it to work.
claytron · 457 weeks and 4 days 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 · 280 weeks and 5 days 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?

commandlinefu.com 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.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

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: