使用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 sshdHow 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 grepgives 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"更多推荐
发布评论