Jakub M. Jakub M. - 1 month ago 16
Linux Question

More elegant "ps aux | grep -v grep"

When I check list of processes and 'grep' out those that are interesting for me, the

grep
itself is also included in the results. For example, to list terminals:

$ ps aux | grep terminal
user 2064 0.0 0.6 181452 26460 ? Sl Feb13 5:41 gnome-terminal --working-directory=..
user 2979 0.0 0.0 4192 796 pts/3 S+ 11:07 0:00 grep --color=auto terminal


Normally I use
ps aux | grep something | grep -v grep
to get rid of the last entry... but it is not elegant :)

Do you have a more elegant hack to solve this issue (apart of wrapping all the command into a separate script, which is also not bad)

Answer

The usual trick is this:

ps aux | grep '[t]erminal'

This will match lines containing terminal, which grep '[t]erminal' does not! It also works on many flavours of Unix.