lsof -c标志过滤掉了什么?

lsof将显示一个表,第一列是命令名,每一行是一个打开的文件。 所以为了只显示特定命令的行,说“java”,这是有道理的,试试lsof | grep ^java lsof | grep ^java 。 这工作,但我知道lsof有它自己的标志来限制输出只有特定的命令 – -c 。 但是当我尝试使用lsof -c java ,输出是完全不同的。 -c方法只输出大约10行,而grep方法输出数千行。

所以我的问题是 – lsof -c滤除了什么?

既然这个问题得到了回应,我会详细说明。 问题的原因是grep方法lsof | grep ^java lsof | grep ^java理论上应该和lsof -c java输出一样。 我的推理是这样的 –

lsof | grep ^java lsof | grep ^java将仅显示以字母“java”开头的行,并且lsof输出的每一行的开始是打开该文件的命令的名称。

lsof -c java应该只显示以字母“java”开头的命令打开的文件。 命令名称位于lsof输出的每一行的开头。

我不知道该怎么解释。

为了回答yoonix的评论,这是lsof man页面对-c标志所说的内容。 你应该先阅读它,然后才build议我读一下它的答案:

  -cc selects the listing of files for processes executing the command that begins with the characters of c. Multiple commands may be specified, using multiple -c options. They are joined in a single ORed set before participating in AND option selection. If c begins with a `^', then the following characters specify a command name whose processes are to be ignored (excluded.) If c begins and ends with a slash ('/'), the characters between the slashes are interpreted as a regular expression. Shell meta-characters in the regular expression must be quoted to prevent their interpretation by the shell. The closing slash may be followed by these modifiers: b the regular expression is a basic one. i ignore the case of letters. x the regular expression is an extended one (default). See the lsof FAQ (The FAQ section gives its location.) for more information on basic and extended regular expressions. The simple command specification is tested first. If that test fails, the command regular expression is applied. If the simple command test succeeds, the command regular expression test isn't made. This may result in ``no command found for regex:'' mes‐ sages when lsof's -V option is specified. 

lsof | grep的PHP

它将过滤包含php的lsof命令输出中的所有行,如下面的子string

apache2 26964 / usr / lib / php /20151012/wddx.so apache2 26964 / usr / lib / php /20151012/tokenizer.so apache2 26964 / usr / lib / php /20151012/sysvshm.so apache2 26964 / usr / lib / php /20151012/sysvsem.so

在哪里作为lsof -c php

为执行以字符php开头的命令的进程select文件列表

例如

PHP-fpm7。 1775 /lib/x86_64-linux-gnu/libpthread-2.23.so

PHP-fpm7。 1775 /lib/x86_64-linux-gnu/libc-2.23.so

PHP-fpm7。 1775 /lib/x86_64-linux-gnu/libcrypto.so.1.0.0

PHP-fpm7。 1775 /lib/x86_64-linux-gnu/libssl.so.1.0.0

PHP-fpm7。 1775 /usr/lib/x86_64-linux-gnu/libxml2.so.2.9.4

希望错配的原因是明确的