使用ps | egrep时过滤排除掉egrep自身
博文背景
root@shanghai:/usr/local/redis-7.0.3# ps -ef | egrep redis
root 1815199 1 0 00:00 ? 00:01:28 ./src/redis-server 127.0.0.1:6379
root 1997222 1996120 0 19:23 pts/2 00:00:00 grep -E --color=auto redis
这个很丑陋,看着不习惯
root@shanghai:/usr/local/redis-7.0.3# ps -ef | egrep redis | egrep -v grep
root 1815199 1 0 00:00 ? 00:01:28 ./src/redis-server 127.0.0.1:6379
这个很麻烦,看着不习惯
解决办法
% ps -ef | egrep "[r]edis"
root@shanghai:/usr/local/redis-7.0.3# ps -ef | egrep "[r]edis"
root 1815199 1 0 00:00 ? 00:01:28 ./src/redis-server 127.0.0.1:6379
原理自己领悟,想想就很容易懂了。
参考链接:https://www.baeldung.com/linux/grep-exclude-ps-results#2-make-a-grep-expression-that-excludes-grep-itself
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
