侧边栏壁纸
博主头像
可乐呢o3o博主等级

少些比较,多些谦虚。

  • 累计撰写 53 篇文章
  • 累计创建 67 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

Grep如何过滤自己

liuker
2023-07-14 / 0 评论 / 0 点赞 / 52 阅读 / 1396 字

要想在使用grep时不显示自己,常规有下面两种做法

ps -ef | grep "nginx" |grep -v "grep" 
ps -ef | grep "[n]ginx"

grep -v 过滤grep自身可以通过man获取帮助。但是grep “[n]ginx”是如何实现不显示grep本身的了?

ps -ef | grep "[n]ginx"命令中,grep 命令的参数是正则表达式"[n]ginx" ,正则表达式"[n]ginx" 可以匹配文本"nginx" ,但是不能匹配"[n]ginx"

PS:我们使用grep时,也可能这样写ps -ef | grep [n]ginx (即grep的参数不带引号),虽然也是能工作,但是man文档建议大家还是要用引号包裹参数。

man grep:
grep searches for PATTERNS in each FILE. PATTERNS is one or more patterns separated by newline characters, and grep prints each line that matches a pattern. Typically PATTERNS should be
quoted when grep is used in a shell command.

0

评论区