ps aux | grep firefox
Lists all processes having the string "firefox"
ps aux | grep -v firefox
Lists all the processes without the string "firefox"
ps aux | grep -v grep | grep firefox
?
What does this second grep does ? grep itself is a command then why we are grepping another grep ?
Best Answer
When you do a command such as
Then the
grep
process itself may show in the output because the word you are looking for is present. e.g. on my machine I runchrome
and the similar results:We can see process 3384 is the
grep
command and matches because the word chrome shows up.To avoid this some people then add a second
| grep -v grep
to remove that line.There is a cheat though...
grep '[f]irefox'
matches exactly the same lines asgrep firefox
, but now thegrep
command will never match itself because the word doesn't literally appear on that command.