当我检查进程列表并“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/