组合多个 lsof 选项

组合多个 lsof 选项

有什么办法可以将 the-i-p的选项组合lsof成逻辑连接吗?在我看来,默认行为是显示满足一个或另一个条件的文件,我认为这有点奇怪。

答案1

使用-a其中之一所示的选项lsof手册页中的示例

To list all open IPv4 network files in use by the process whose
PID is 1234, use:

       lsof -i 4 -a -p 1234

“选项”部分解释:

Normally list options that are specifically stated are ORed -
i.e., specifying the -i option without an address and the -ufoo
option produces a listing of all network files OR files belonging
to processes owned by user ``foo''.  The exceptions are:

[…]

The -a option may be used to AND the selections.  For example,
specifying -a, -U, and -ufoo produces a listing of only UNIX
socket files that belong to processes owned by user ``foo''.

Caution: the -a option causes all list selection options to be
ANDed; it can't be used to cause ANDing of selected pairs of
selection options by placing it between them, even though its
placement there is acceptable.  Wherever -a is placed, it causes
the ANDing of all selection options.

Items of the same selection set - command names, file
descriptors, network addresses, process identifiers, user
identifiers, zone names, security contexts - are joined in a
single ORed set and applied before the result participates in
ANDing.  Thus, for example, specifying [email protected], [email protected],
-a, and -ufff,ggg will select the listing of files that belong to
either login ``fff'' OR ``ggg'' AND have network connections to
either host aaa.bbb OR ccc.ddd.

[…]

-a     causes list selection options to be ANDed, as described
       above.

相关内容