如何ps aux | grep'[p] attern'exclude grep本身? [英] How does ps aux | grep '[p]attern' exclude grep itself?

查看:183
本文介绍了如何ps aux | grep'[p] attern'exclude grep本身?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题说的一切。我已经看过这个成语,而不是在一些 ps 管道中添加额外的 grep -v grep 例如,它可以这样使用:

  $ ps aux | grep'[f] irefox'| awk'{print $ 8}'

而不是

  $ ps aux | grep'firefox'| grep -v grep | awk'{print $ 8}'

这非常方便,但它是如何工作的,为什么? / p>

解决方案

模式 [f] irefox 将不匹配字符串 [f] irefox 。相反,它将匹配字符串与1字符类 [f] 中的一个字符,后跟 irefox 。 / p>

The title says it all. I've seen this idiom used alot instead of adding an additional grep -v grep in some ps pipeline. For example it could be used like this:

$ ps aux | grep '[f]irefox' | awk '{ print $8 }'

instead of

$ ps aux | grep 'firefox' | grep -v grep | awk '{ print $8 }'

It's super-convenient, but how does it work and why?

解决方案

The pattern [f]irefox will not match the literal string [f]irefox. Instead it will match strings with exactly one char from the 1-character class [f], followed by irefox.

这篇关于如何ps aux | grep'[p] attern'exclude grep本身?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆