複数のlsofオプションを組み合わせる

複数のlsofオプションを組み合わせる

-i-pオプションをlsof論理接続に結合する方法はありますか?デフォルトの動作は、1つまたは別の条件を満たすファイルを表示するようですが、少し奇妙だと思います。

ベストアンサー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.

おすすめ記事