使用awk批量殺進程的命令:
ps -ef | grep firefox | grep -v grep | awk '{print "kill -9 "$2}'|sh
說明:
#列出了當前主機中運行的進程中包含firefox關鍵字的進程 ps -ef | grep firefox | grep -v grep #列出了要kill掉這些進程的命令,並將之打印在了屏幕上 ps -ef | grep firefox | grep -v grep | awk '{print "kill -9 "$2}' #后面加上|sh后,則執行這些命令,進而殺掉了這些進程 ps -ef | grep firefox | grep -v grep | awk '{print "kill -9 "$2}' | sh
使用cut批量殺進程的命令:
ps -ef | grep firefox | grep -v grep | cut -c 9-15 | xargs kill -9
說明:
#列出了當前主機中運行的進程中包含firefox關鍵字的進程 ps -ef | grep firefox | grep -v grep #截取第9至15字符(進程id),列出了要kill掉這些進程的id,並將之打印在了屏幕上 ps -ef | grep firefox | grep -v grep | cut -c 9-15 #后面加上'xargs kill -9'后,則執行這些命令,進而殺掉了這些進程 ps -ef | grep firefox | grep -v grep | cut -c 9-15 | xargs kill -9