exclude grep on ps a | grep

Have you ever tried to grep for a process, and saw grep show up too? annoying, right?

$ ps aux | grep "python"  
8714 pts/2 S+ 0:00 python
8716 pts/1 S+ 0:00 grep -color python

Well, turns out Wayne Werner found a cool solution!

$ ps aux | grep "[p]ython"  
8714 pts/2 S+ 0:00 python

How does it work? By putting the brackets around the letter and quotes around the string, you search for a regex which says - “Find the character ‘p’ followed by ‘ython’”

But since you put the brackets in the pattern p is now followed by ]grep won’t show up in the results list. Why? because its text is “grep -color [p]ython” and not “grep -color python”.