IT系ノウハウ Linux

ps コマンドを特定のカラムでソートして表示させる方法|昇順と降順

--sort オプションを使うことで特定のカラムで並び替えることが可能

降順

大きい順に並び替えるときは、カラム名の前に - マイナスをつける。

[oracle@hellomyworld ~]$ ps aux --sort -%mem | head
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
oracle    5469  0.0 15.5 2198096 908788 ?      Ss   10月15   1:19 ora_dbw0_orcl
oracle    5445  0.0  8.6 2189584 502852 ?      Ss   10月15   0:12 ora_mman_orcl
oracle    7368 25.2  7.8 2195620 459040 ?      Ss   16:37   0:04 ora_j000_orcl
oracle    5554  0.0  6.7 2198756 395784 ?      Ss   10月15   7:57 ora_cjq0_orcl
oracle    5495  0.0  5.1 2233352 302980 ?      Ss   10月15   2:55 ora_mmon_orcl
gdm       5156  0.0  3.3 3261900 194660 ?      Sl   10月15   2:33 /usr/bin/gnome-shell
oracle    5477  0.0  3.0 2192488 180080 ?      Ss   10月15   0:10 ora_smon_orcl
oracle    7370  1.3  2.4 2191492 142576 ?      Ss   16:37   0:00 ora_j001_orcl
oracle    5459  0.0  2.0 2210720 117428 ?      Ss   10月15   3:51 ora_dbrm_orcl

昇順

小さい順に並び替えるときは、カラム名の前に + プラスをつける。

[oracle@hellomyworld ~]$ ps aux --sort +%mem | head
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         2  0.0  0.0      0     0 ?        S    10月15   0:00 [kthreadd]
root         4  0.0  0.0      0     0 ?        I<   10月15   0:00 [kworker/0:0H]
root         6  0.0  0.0      0     0 ?        I<   10月15   0:00 [mm_percpu_wq]
root         7  0.0  0.0      0     0 ?        S    10月15   0:00 [ksoftirqd/0]
root         8  0.0  0.0      0     0 ?        I    10月15   1:01 [rcu_sched]
root         9  0.0  0.0      0     0 ?        I    10月15   0:00 [rcu_bh]
root        10  0.0  0.0      0     0 ?        S    10月15   0:00 [migration/0]
root        11  0.0  0.0      0     0 ?        S    10月15   0:01 [watchdog/0]
root        12  0.0  0.0      0     0 ?        S    10月15   0:00 [cpuhp/0]

この記事が役に立ったという方は
ボタンをポチッとしてくれたら喜びます

-IT系ノウハウ, Linux
-,