本文介绍了更优雅的"ps aux |grep -v grep"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我检查进程列表并grep"出我感兴趣的进程时,grep 本身也包含在结果中.例如,列出终端:

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

通常我使用 ps aux |grep 的东西|grep -v grep 去掉最后一个条目......但它不优雅 :)

Normally I use ps aux | grep something | grep -v grep to get rid of the last entry... but it is not elegant :)

你有没有更优雅的 hack 来解决这个问题(除了将所有命令包装到一个单独的脚本中,这也不错)

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)

推荐答案

通常的技巧是这样的:

ps aux | egrep '[t]erminal'

这将匹配包含 terminal 的行,而 egrep '[t]erminal' 不匹配!它也适用于许多 Unix 版本.

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"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 12:07