查找某进程 但过滤grep进程本身 方法

在进程表中查找特定进程的命令通常如下:

 

[python]  view plain  copy
 
  1. ps -ef | grep some_string  

输出时,不仅会输出将要查找的进程数据,清空包括grep进程本身的数据,因为查找串包含在grep调用中。过滤grep本身方法有:

 

ps -ef | grep some_string |grep -v grep

-v:表示忽略grep本身。

 

还有一个方法:

 

[python]  view plain  copy
 
  1. ps -ef | grep [s]ome_string  

即将要查找的串变为一个正则表达式。因为grep进程的条目显示处理命令优先于正则表达式([s]ome_string)。当grep命令运行时,grep进程自身的条目不匹配,就没有包括在输出中了。

 

使用egrep一次查找多个串:
[python]  view plain  copy
 
  1. egrep "desktop|mysql|ntp" /etc/passwd"  

+

+

+

=

=

=

猜你喜欢

转载自fantaxy025025.iteye.com/blog/2309127
今日推荐