Pipe ps to kill

Single Process#

If you want kill a running process called main.py, you could do

$ ps | grep main | grep py
$ kill -9 <pid>

but that's a hassle. To do it in one step, you can do

$ kill -9 `ps | grep main | grep py | cut -f 1 -d" "`

Multiple Processes#

If you have many python scripts with 'matterhorn' in the path (visible by doing "ps auxwww") then you can do

$ ps auxwww | grep python | grep matterhorn | awk '{print $2}' | xargs kill -9

What this does is:

CategoryComputing.Linux.Shell - CategoryComputing.Mac.Shell