Say I want to kill every process containing the word amarok. I can print out the commands I want to execute. But how do I actually make the shell execute them. ie.
I think this command killall is exactly what you need. The command is described as "kill processes by name".It's easy to use.For example
killall chrome
This command will kill all process of Chrome.Here is a link about killall command
http://linux.about.com/library/cmd/blcmdl1_killall.htm
Hope this command could help you.
try kill -s 9 ps -ef |grep "Nov 11" |grep -v grep | awk '{print $2}'
To kill processes of November 11
or
kill -s 9 ps -ef |grep amarok|grep -v grep | awk '{print $2}'
To kill processes that contain the word amarok
ps aux | grep -ie amarok | awk '{print $2}' | xargs kill -9
xargs(1): xargs -- construct argument list(s) and execute utility. Helpful when you want to pipe in arguments to something like kill
or ls
or so on.
You can also evaluate your output as a sub-process, by surrounding everything with back ticks or with putting it inside $():
`ps aux | grep -ie amarok | awk '{print "kill -9 " $2}'`
$(ps aux | grep -ie amarok | awk '{print "kill -9 " $2}')
If you want to execute the output of a command, you can put it inside $(...)
, however for your specific task take a look at the killall
and pkill
commands.