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

转载:https://www.cnblogs.com/abeen/p/11080841.html

Talk is cheap, show me the code.
原文地址:https://www.cnblogs.com/cidgur/p/12029734.html