ps aux 怎么样?grep '[p]attern' 排除 grep 本身? [英] How does ps aux | grep '[p]attern' exclude grep itself?

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

问题描述

标题说明了一切.我已经看到这个习语被大量使用,而不是在某些 ps 管道中添加额外的 grep -v grep.例如,它可以像这样使用:

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 }'

代替

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

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

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

推荐答案

模式 [f]irefox 将与文字字符串 [f]irefox 不匹配.相反,它将匹配来自 1 个字符的类 [f] 中的一个字符的字符串,后跟 irefox.

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' 排除 grep 本身?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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