How do I ignore grep process ID (PID) in Linux?

I want to exclude grep from ps and other command line results. I run

ps aux | grep firefox

Apart from firefox I will always see grep too:

tomboi     269078  9.5  1.2 3276832 399220 ?      Sl   12:49   1:40 /usr/lib/firefox/firefox
tomboi     269139  0.2  0.4 2501820 161032 ?      Sl   12:49   0:02 /usr/lib/firefox/firefox -contentproc -childID 1 -isForBrowser -prefsLen 1 -prefMapSize 248604 -parentBuildID 20210504152106 -appdir /usr/lib/firefox/browser 269078 true tab
tomboi     269188  1.6  0.6 34044296 201604 ?     Sl   12:49   0:17 /usr/lib/firefox/firefox -contentproc -childID 2 -isForBrowser -prefsLen 5573 -prefMapSize 248604 -parentBuildID 20210504152106 -appdir /usr/lib/firefox/browser 269078 true tab
tomboi     269281  2.7  1.1 2994448 377868 ?      Sl   12:49   0:29 /usr/lib/firefox/firefox -contentproc -childID 3 -isForBrowser -prefsLen 6266 -prefMapSize 248604 -parentBuildID 20210504152106 -appdir /usr/lib/firefox/browser 269078 true tab
tomboi     271513  0.0  0.0   9032  2680 pts/0    S+   13:07   0:00 grep --color=auto firefox

So how can I ignore grep process ID (PID and PS) in Linux?

The grep command also appear in their own results. This is known issue.

Finding process ID (PID) in Linux

Looking for a Specific process is done using the grep:

ps aux | grep PID
ps aux | grep 'process-name'
ps aux | grep 'google-chrome'

Ignoring grep process ID

We can do that using grep itself :wink:

ps aux | grep PID | grep -v grep
ps aux | grep 'process-name' | grep -v grep
ps aux | grep 'google-chrome' | grep -v grep
1 Like

There is another option with grep regex:

ps aux | grep "[f]irefox"
# look for getty PID
ps aux | grep "[g]etty"

See my page for more info

1 Like

Linux sysadmin blog - Linux/Unix Howtos and Tutorials - Linux bash shell scripting wiki