linux - 更优雅 "ps aux | grep -v grep"

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

$ 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 摆脱最后一个条目......但它不是优雅 :)

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

最佳答案

通常的技巧是这样的:

ps aux | egrep '[t]erminal'

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

https://stackoverflow.com/questions/9375711/

相关文章:

linux - httpd : Could not reliably determine the s

python - django 导入错误 - 没有名为 core.management 的模块

linux - 解压目录中的所有文件

linux - 使用脚本自动输入 SSH 密码

linux - 是否有适用于 Linux 的 WinSCP?

python - 检查字符串是否仅包含空格

python - 重定向到 Flask 中的 URL

python - 如何将整数转换为任何基数的字符串?

linux - 强制卸载 NFS 挂载的目录

python - 您如何以编程方式设置属性?