如果我写ps -ef
,则返回当前运行的所有进程。如果我键入ps -ef | grep xxx
,则它返回使用子字符串xxx
运行的所有进程。但ps -ef | grep xxx
也是当前流程,因此它也会在列表中返回grep xxx
。
我只想从列表中删除grep xxx
。
任何人都可以帮我这个。
感谢
答案 0 :(得分:2)
尝试这样做:
pgrep -fl xxx
另一种解决方案
ps -ef | grep '[x]xx'
这是一个避免重复的简单正则表达技巧
pgrep
打包在procps
,Debian:
$ LANG=C apt-cache show procps
Package: procps
Priority: important
Section: admin
Installed-Size: 760
Maintainer: Craig Small <csmall@debian.org>
Replaces: bsdutils (<< 2.9x-1), watch
Provides: watch
Depends: libc6 (>= 2.3.4), libncurses5 (>= 5.7+20100313), libncursesw5 (>= 5.7+20100313), lsb-base (>= 3.0-10), initscripts
Recommends: psmisc
Conflicts: libproc-dev (<< 1:1.2.6-2), pgrep (<< 3.3-5), procps-nonfree, w-bassman (<< 1.0-3), watch
Size: 249178
Description: /proc file system utilities
This package provides command line and full screen utilities for browsing
procfs, a "pseudo" file system dynamically generated by the kernel to
provide information about the status of entries in its process table
(such as whether the process is running, stopped, or a "zombie").
.
It contains free, kill, pkill, pgrep, pmap, ps, pwdx, skill, slabtop,
snice, sysctl, tload, top, uptime, vmstat, w, and watch.
Homepage: http://procps.sf.net/
Tag: admin::monitoring, interface::commandline, interface::text-mode, role::program, scope::utility, uitoolkit::ncurses, use::monitor, works-with::software:running
答案 1 :(得分:1)
而不是说
ps -ef | grep xxx
说
ps -ef | grep [x]xx
并且您不会在输出中看到grep xxx
。 (基本上将所需单词的第一个字符作为字符类[]
。)