grep processes list avoiding the grep itself

ps axu | grep [a]pache2
Trick to avoid the form: grep process | grep - v grep
Sample Output
user@ubuntu:~$ ps axu | grep [a]pache2
root      9399  0.0  0.1 105628  7588 ?        SNs  11:55   0:01 /usr/sbin/apache2 -k start
www-data  9401  0.0  0.1 105716  5576 ?        SN   11:55   0:00 /usr/sbin/apache2 -k start
www-data  9402  0.0  0.1 105716  5572 ?        SN   11:55   0:00 /usr/sbin/apache2 -k start
www-data  9403  0.0  0.1 105668  5028 ?        SN   11:55   0:00 /usr/sbin/apache2 -k start
www-data  9404  0.0  0.1 105716  5576 ?        SN   11:55   0:00 /usr/sbin/apache2 -k start
www-data  9405  0.0  0.1 105652  4788 ?        SN   11:55   0:00 /usr/sbin/apache2 -k start
www-data 15581  0.0  0.1 105652  4788 ?        SN   12:04   0:00 /usr/sbin/apache2 -k start
www-data 15582  0.0  0.1 105652  4788 ?        SN   12:04   0:00 /usr/sbin/apache2 -k start
www-data 15583  0.0  0.1 105652  4788 ?        SN   12:04   0:00 /usr/sbin/apache2 -k start

13
By: EBAH
2012-12-15 19:37:19

10 Alternatives + Submit Alt

What Others Think

This works: ps axu | grep apa\\che double backslash can be anywhere within the pattern
tedkozma · 536 weeks and 6 days ago
I use something like this: auxer () { ps aux | grep -i "$(echo "$1" | sed "s/^\(.\)\(.*$\)/\[\1\]\2/")" }
redshadowhero · 536 weeks and 6 days ago
Can someone please explain why this works?
Mikecron · 536 weeks and 3 days ago
I found the explanation given by user "leper421" here: http://www.commandlinefu.com/commands/view/402/exclude-grep-from-your-grepped-output-of-ps-alias-included-in-description 'This works because "[h]ttpd" matches only an "h" followed by "ttpd". The line that is printed by "ps aux" is "[h]ttpd" which includes the brackets, therefor not matching. Clever.'
Mikecron · 536 weeks and 2 days ago
Can also be done with awk: $ ps axu | awk '/[a]pache2/' To extract a PID: $ ps axu | awk '/[a]pache2/ {print $1}' But wasn't pgrep written to solve this ? pgrep -l apache2 pgrep apache2
zlemini · 535 weeks ago
Hi Mikecron, sorry for late reply, this commands works because of regular expression issues. When you use square brakets in a regexp it means: a chararcter part of this set. Example: [a-z]pache: match apache, bpache, cpache, ... , zpache [a]pache: matches only apache So when you type the command it filters all the lines containins the word "apache". If you are able to see the process list (ps -ef) in the exact moment as grep runs you would see a line containing "grep [a]pache". So why the grep process isn't shown? Because regexp([a]pache) != string([a]pache) Hope this is clear. Bye
EBAH · 535 weeks ago
Dear zlemini, I admit I didn't know pgrep. Since I work on a variety of OSes (Linux, Solaris, HP-UX) I tend to be as conservative as possible, so I prefer to use the same command on all the systems instead of variants. One example above all: one script for all OSes instead of three is easier to maintain. Anyway I'll have a look to the pgrep, I'm courious. Thanks!
EBAH · 535 weeks ago
Thanks for your post. I’ve been thinking about writing a very comparable post over the last couple of weeks, I’ll probably keep it short and sweet and link to this instead if thats cool. Thanks. trash chute fire discharge door
Audrey10 · 35 weeks and 5 days ago
pugs puppies for sale teacup pugs for sale pug puppies for sale by owner pug puppies ohio PUG PUPPY FOR SALE NEAR ME PUG PUPPIES FOR SALE pug puppies for sale in kentucky Pug Puppies for Sale Under $500 Near Me pug puppies for sale in texas Pug Puppies for Sale Near Me Amazing! This blog looks just like my old one! It's on a completely different subject but it has pretty much the same layout and design. Wonderful choice of colors!
rahimhh21 · 31 weeks and 2 days ago
Pug Puppies for Sale Near Me pugs puppies for sale teacup pugs for sale pug puppies for sale by owner pug puppies ohio PUG PUPPY FOR SALE NEAR ME PUG PUPPIES FOR SALE pug puppies for sale in kentucky Pug Puppies for Sale Under $500 Near Me pug puppies for sale in texas pug puppies for sale $200 pugs for sale near me under $500 pugs for sale under $400 near me pugs for sale near me puppies for sale near me under $500 pug puppies for sale under $1,000 near me pug for sale pug puppies for sale under $300 Brindle Pug Pitbull Pug Mix Pugs for sale cheap Cheap pug affordable pug puppies for sale near me black pugs for sale near me White Pugs for sale pug dog for sale free pug puppies pug puppies for sale in my area mn pug breeders pug puppies indiana pugs for sale michigan PUG PUPPY ADOPTION Pug puppies for sale Pug puppies for sale near me Pug puppies near me Pug Puppies for Sale Under $500 Near Me Cute Pug Puppies Black pug puppies Black pug puppies for sale pug puppies for adoption black pug puppies for sale near me chihuahua pug mix puppies how much is a pug puppy teacup pug puppies baby pug puppies baby pug puppies for sale pictures of pug puppies pug puppies for sale in Ohio pug puppies price pug mix puppies teacup pug puppies for sale best food for pug puppy newborn pug puppies pug puppies craigslist pug puppies for sale craigslist adorable pug puppies how much does a pug puppy cost Pitbull pug mix puppies pug pit mix puppy pug puppies for sale $200 pug puppies for sale in NJ Pug puppies for sale in Wisconsin pug puppy cost pug puppy food royal canin pug puppy royal canin pug puppy food fawn pug puppy pug puppies for sale florida pug puppies for sale in Indiana pug puppies for sale in KY pug puppies for sale in NC pug dog puppy AKC Registered Pug Puppies For sale cheap pug puppies for sale near me cheap pug puppies for sale in California cheap pug puppies for sale in nj Black Pug Puppies for sale pugs puppies for sale
Perfecthomepugs · 22 weeks and 1 day ago
I love your blog site.. great colorings & style. Did a person style and design this fabulous website you as well as have you actually hire an attorney to make it work to suit your needs? Plz respond as I!|m looking to layout my own, personal weblog in addition to would wish to understand in which ough bought the following via. appreciate it Retro cars
mahmishal · 21 weeks and 2 days ago
Audio started playing anytime I opened up this blog, so annoying! RTP live hari ini
HAMZA · 20 weeks and 6 days ago
Hi! Thanks for the great information you have provided! You have touched on crucial points! Psychiatrist
sophiacharlie · 19 weeks and 5 days ago
Youre so cool! I dont suppose Ive read anything like that before. So nice to seek out somebody with some original applying for grants this subject. realy we appreciate you beginning this up. this excellent website is one area that is needed on-line, a person with a little originality. useful purpose of bringing a new challenge towards web! ??????
gabis31 · 18 weeks and 6 days ago
Youre so cool! I dont suppose Ive read anything like that before. So nice to seek out somebody with some original applying for grants this subject. realy we appreciate you beginning this up. this excellent website is one area that is needed on-line, a person with a little originality. useful purpose of bringing a new challenge towards web! ??????
gabis31 · 18 weeks and 6 days ago
As I website possessor I believe the written content here is really fantastic , appreciate it for your efforts. slot
goxah55535 · 18 weeks and 4 days ago
Very well said, your blog says it all about that particular topic.,:~`” have a peek at this site
mahmishal · 14 weeks and 6 days ago
This is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work!. zeus88
HAMZA · 14 weeks ago
I prefer the countless blogposts, My partner and i significantly enjoyed, I would like information regarding that, given that it is extremely great., Many thanks related to articulating. official website
mahmishal · 13 weeks and 3 days ago
It’s difficult to get knowledgeable men and women with this topic, and you appear to be what happens you are dealing with! Thanks pop over here
lahehan967 · 13 weeks and 3 days ago
You made some respectable points there. I seemed on the internet for the problem and located most individuals will associate with together with your website. debouchage bruxelles
wenilak444 · 13 weeks and 3 days ago
That is a really amazing powerful resource that you’re offering and you just provide it away cost-free!! I that can compare with discovering websites which comprehend the particular valuation on providing you with fantastic learning resource for zero cost. We truly dearly loved examining this web site. Have fun here! juragan slot88
mahmishal · 13 weeks ago
I love the look of your website. I recently built mine and I was looking for some ideas for my site and you gave me a few. May I ask you whether you developed the website by youself? Link Bong88
mahmishal · 12 weeks and 6 days ago
I felt very happy while reading this site. This was really very informative site for me. I really liked it. This was really a cordial post. Thanks a lot!. agen sbobet terpercaya
HAMZA · 12 weeks and 4 days ago
I’m not sure exactly how I discovered your blog because I had been researching information on Real Estate in Altamonte Springs, FL, but anyway, I have had a pleasant time reading it, keep it up! gta79
gabis31 · 12 weeks and 2 days ago
Nice post. I find out some thing tougher on different blogs everyday. Most commonly it is stimulating to study content from other writers and employ something from their site. I’d choose to apply certain together with the content in this little weblog no matter whether you do not mind. Natually I’ll give you a link on your web blog. Thank you for sharing. Brigade Valencia
lahehan967 · 7 weeks and 4 days ago
You definitely know how to bring an issue to light and make it important. I cant believe youre not more popular because you definitely have the gift. west palm beach financial advisor
mahmishal · 6 weeks and 2 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: