UID / GIDを出力の一部として表示するために、「ps -Af」に「-o」オプションを追加できますか?

UID / GIDを出力の一部として表示するために、「ps -Af」に「-o」オプションを追加できますか?

ps -f強力な基本出力列セットを提供するので、非常に便利だと思います。

しかし、UID/GIDなどを出力の一部として表示したい場合も多いです。たとえば、次のようにps -o出力列セットに出力列を追加できますか?ps -f

parallels@debian-gnu-linux-vm:~$ ps -Af -o gid,uid | grep sleep
error: conflicting format options

Usage:
 ps [options]

 Try 'ps --help <simple|list|output|threads|misc|all>'
  or 'ps --help <s|l|o|t|m|a>'
 for additional help text.

For more details see ps(1).

また、コマンドをgrepingするときに列ヘッダーを見逃さないようにgrep組み込みのものはありますか?ps

man ps:

-o format
              User-defined format.  format is a single argument in the form of a blank-separated or comma-separated list, which
              offers a way to specify individual output columns.  The recognized keywords are described in the STANDARD FORMAT
              SPECIFIERS section below.  Headers may be renamed (ps -o pid,ruser=RealUser -o comm=Command) as desired.  If all
              column headers are empty (ps -o pid= -o comm=) then the header line will not be output.  Column width will increase as
              needed for wide headers; this may be used to widen up columns such as WCHAN (ps -o pid,wchan=WIDE-WCHAN-COLUMN -o
              comm).  Explicit width control (ps opid,wchan:42,cmd) is offered too.  The behavior of ps -o pid=X,comm=Y varies with
              personality; output may be one column named "X,comm=Y" or two columns named "X" and "Y".  Use multiple -o options when
              in doubt.  Use the PS_FORMAT environment variable to specify a default as desired; DefSysV and DefBSD are macros that
              may be used to choose the default UNIX or BSD columns.

ベストアンサー1

この-Oオプションを使用してデフォルトの選択に列を追加できますが、一致しません-fps -O uid,gidshow pid、uid、gid、status、tty、time、command)。 (マンページには、「System V」対「BSD」モードに該当すると考えられる「状態非保存」バリエーションが挙げられているが、列の定義-Oこれはサポートされていません。 )

特定の列セットが必要な場合は、procps-ngsを使用して完全に指定する必要があります。psこれは-f-o uid_hack,pid,ppid,c,stime,tname,time,cmd)、列の後にuidとgidを追加しますuid_hack。はい

$ ps -o uid_hack,uid,gid,pid,ppid,c,stime,tname,time,cmd

procps-ng「マクロ」もサポートされています。これらのマンページには「DefBSD」と「DefSysV」が記載されています。他の定義もたくさんありますStd_f、次の設定が含まれます-f

$ ps -o Std_f,uid,gid

psさまざまな検索基準を使用して出力をフィルタリングできsleepます-C

$ ps -C sleep -o uid_hack,uid,gid,pid,ppid,c,stime,tname,time,cmd

おすすめ記事