正在加载...
分页: 1/1 第一页 1 最后页 [ 显示模式: 摘要 | 列表 ]

shell grep 查找进程的小技巧

[ 2012/12/29 17:34 | by selboo ]
        大部分人在写Shell 过滤进程的时候  都会使用 grep  在 ps aux 的输出结果中查找指定的进程,但此时也会把 grep 进程也显示出来 比如查找 pptpd 进程,会匹配出来两条:

This is The Code
[root@selboo ~]# ps aux | grep pptp
root     20191  0.0  0.2   5108   704 pts/2    R+   16:58   0:00 grep pptp
root     22054  0.0  0.1   1952   608 ?        Ss   Oct22   0:00 /usr/sbin/pptpd
Parsed in 0.000 seconds at N/A

常见的防止grep进程出现的方法就是在对加一个管道 grep -v grep 进行过滤:

This is The Code
[root@selboo ~]# ps aux | grep pptp | grep -v grep
root     22054  0.0  0.1   1952   608 ?        Ss   Oct22   0:00 /usr/sbin/pptpd
Parsed in 0.000 seconds at N/A

还有一个更方便的方法是用 正则 grep [p]ptpd来搜索pptpd这个进程:

This is The Code
[root@selboo ~]# ps aux | grep [p]ptp  
root     22054  0.0  0.1   1952   608 ?        Ss   Oct22   0:00 /usr/sbin/pptpd
Parsed in 0.000 seconds at N/A

分页: 1/1 第一页 1 最后页 [ 显示模式: 摘要 | 列表 ]