Shell One Liner: Kill process by name 1

You probably came across the situation in linux, unix, or OS X where a bad cron job or shell script spawned a large number of processes of the same kind and you want to kill them all.
They usually have the same name. The following one-liner greps the name from ps, removes the grep process from the list, gets the pids with awk, and then kills the list of processes. All in one line thanks to pipe and command expansion with backticks.

$ kill -9 `ps -aef | grep 'PROCESS-NAME' | grep -v grep | awk '{print $2}'`

One comment on “Shell One Liner: Kill process by name

  1. Reply Frazer Jan 18,2018 16:20

    thanks… super helpful

Leave a Reply




This site uses Akismet to reduce spam. Learn how your comment data is processed.