更优雅的“ps aux |” grep -v grep“ [英] More elegant "ps aux | grep -v grep"
问题描述
当我检查进程列表并grep出那些对我有意思的内容时,结果中也包含 grep
本身。例如,要列出终端:
$ ps aux | grep终端
用户2064 0.0 0.6 181452 26460? Sl Feb13 5:41 gnome-terminal --working-directory = ..
user 2979 0.0 0.0 4192 796 pts / 3 S + 11:07 0:00 grep --color = auto terminal
通常我使用 ps aux | grep something | grep -v grep
来摆脱最后一项...但它不是优雅的:)
你是否有更优雅的黑客来解决这个问题(除了把所有的命令包装到一个单独的脚本中,这也是一件坏事)
解决方案通常的技术是这样的:
ps aux | egrep'[t] erminal'
这将匹配包含 code>,其中
egrep'[t] erminal'
不!它也适用于Unix的 许多 。
When I check list of processes and 'grep' out those that are interesting for me, the grep
itself is also included in the results. For example, to list terminals:
$ ps aux | grep terminal
user 2064 0.0 0.6 181452 26460 ? Sl Feb13 5:41 gnome-terminal --working-directory=..
user 2979 0.0 0.0 4192 796 pts/3 S+ 11:07 0:00 grep --color=auto terminal
Normally I use ps aux | grep something | grep -v grep
to get rid of the last entry... but it is not elegant :)
Do you have a more elegant hack to solve this issue (apart of wrapping all the command into a separate script, which is also not bad)
The usual technique is this:
ps aux | egrep '[t]erminal'
This will match lines containing terminal
, which egrep '[t]erminal'
does not! It also works on many flavours of Unix.
这篇关于更优雅的“ps aux |” grep -v grep“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!