gpt4 book ai didi

linux - 使用 grep 过滤进程

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:38:22 24 4
gpt4 key购买 nike

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 美元。所以我在终端中的输入是 ./script_file sshd 以获得上面的输出。有什么建议么?

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

没有给我任何输出。

最佳答案

您可以使用 pgrep。它在大多数现代 Linux 和 Unix 系统上可用(在 OSX 上可通过 home brew 获得):

pgrep -fl "$1"

关于linux - 使用 grep 过滤进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21685978/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com