How to kill all processes apart from specific one
Give a try to this command:
ps ax | grep "java" | egrep -v "eclipse" | cut -b1-06 | xargs -t kill
this will search for all processes containing java and execluding eclipse then kill them
Using awk
ps ax | awk '/java/ && !/eclipse/ {system("kill "$1)}'
The command kills all java
processes, but not the process eclipse
.
How about :
pgrep -af 'java' | grep -Po '^[^ ]+(?!.*eclipse)' | xargs kill
pgrep -af 'java'
searches forjava
in the full command line of the processes and list themgrep -Po '^[^ ]+(?!.*eclipse)'
looks among the searched processes and get the process IDs of the processes that do not haveeclipse
in their full command linesxargs kill
will kill the processes.