使用grep过滤进程(Using grep to filter process)

编程入门 行业动态 更新时间:2024-10-25 23:21:36
使用grep过滤进程(Using grep to filter process) root 1626 1 0 04:49 ? 00:00:00 /usr/sbin/sshd USERNAME 5133 5038 0 14:12 pts/0 00:00:00 /bin/bash ./find_proc.sh sshd USERNAME 5137 5133 0 14:12 pts/0 00:00:00 grep sshd

我如何使用grep过滤底部进程?

ps -ef | grep "$1"

是什么让我输出。 我知道你需要使用grep -v来过滤它,但是我不确定它的顺序。它需要一个$ 1的Argument。 所以我在终端的输入是./script_file sshd来获取上面的输出。 有什么建议么?

ps -ef | grep "$1" | grep -v grep

没有输出。

root 1626 1 0 04:49 ? 00:00:00 /usr/sbin/sshd USERNAME 5133 5038 0 14:12 pts/0 00:00:00 /bin/bash ./find_proc.sh sshd USERNAME 5137 5133 0 14:12 pts/0 00:00:00 grep sshd

How can i use grep to filter out the bottom to processes?

ps -ef | grep "$1"

is what gets me that output. I know you need to use grep -v to filter it out, however i am not sure of the order to do it in. It takes an Argument which is $1. So my input in the terminal is ./script_file sshd to get the output above. Any suggestions?

ps -ef | grep "$1" | grep -v grep

gives me no output.

最满意答案

你可以使用pgrep 。 大多数现代Linux和Unix系统都可以使用它(在home brew OSX上可用):

pgrep -fl "$1"

You can use pgrep. It is available on most of the modern Linux and Unix systems (on OSX available via home brew):

pgrep -fl "$1"

更多推荐

本文发布于:2023-08-01 18:48:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1363641.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:进程   grep   process   filter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!