0

如果我写ps -ef,那么它会返回当前运行的所有进程。如果我键入ps -ef | grep xxx,则它返回所有使用 substring 运行的进程xxx。但ps -ef | grep xxx也是一个当前进程,所以它grep xxx也会在列表中返回。

我只想grep xxx从列表中删除。

谁能帮我这个。
谢谢

4

2 回答 2

2

尝试这样做:

pgrep -fl xxx

另一种解决方案

ps -ef | grep '[x]xx'

这是避免重复的简单正则表达式技巧

pgrep打包在procpsDebian 上:

$ 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
于 2013-10-29T06:45:28.733 回答
1

而不是说

ps -ef | grep xxx

ps -ef | grep [x]xx

你不会grep xxx在输出中看到。(本质上是将所需单词的第一个字符作为字符类[]。)

于 2013-10-29T06:50:08.570 回答