--> 在日常使用Linux的时候经常需要用grep匹配ps输出的进程信息,得到的信息都会有grep行,如:
[root@supersun.biz network]#ps aux |grep firefox
root 4123 0.0 0.2 5160 1192 ? S 14:51 0:00 /bin/sh /usr/bin/firefox
root 4134 0.0 0.2 5160 1212 ? S 14:51 0:00 /bin/sh /root/firefox/run-mozilla.sh /root/firefox/firefox-bin
root 4139 5.6 18.6 249584 92788 ? Sl 14:51 6:55 /root/firefox/firefox-bin
root 5342 0.0 0.1 4612 732 pts/0 R+ 16:54 0:00 grep firefox
如果我们需要对上面的输出进一步处理的话就会需要将grep行去掉,经常这样的话会惹人烦,下面一个grep的技巧,可以方便的去掉grep行,如下:
[root@supersun.biz network]#ps aux |grep [f]irefox
root 4123 0.0 0.2 5160 1192 ? S 14:51 0:00 /bin/sh /usr/bin/firefox
root 4134 0.0 0.2 5160 1212 ? S 14:51 0:00 /bin/sh /root/firefox/run-mozilla.sh /root/firefox/firefox-bin
root 4139 5.6 18.6 249584 92788 ? Sl 14:51 6:55 /root/firefox/firefox-bin
另外可以参考以前的文章
两个小脚本一个用于去注释一个用于列出或杀死匹配的程序
中的列出或杀死匹配的进程序,挺方便的:
[root@supersun.biz network]#lkp firefox l
root 4139 /root/firefox/firefox-bin
如果想杀死匹配的进程:
[root@supersun.biz network]#lkp firefox k

发表评论