Linux 批量殺進程的命令

使用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
相關文章
相關標籤/搜索