Search code examples
linuxps

how to get certain columns from ps aux


Im using ps aux to ouput the top 10 processes on my computer sorted by memory. This is the command that I have:

ps aux --sort %mem --cols 100 |tail -10

This outputs something like

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
dmak1112  3564  0.0  1.2 831788 104588 ?       Sl   12:59   0:01 /opt/google/chrome/chrome --type=re
dmak1112  9227  7.6  1.4 843500 117664 ?       Sl   14:33   0:07 /opt/google/chrome/chrome --type=re
dmak1112  2656  1.7  1.5 1513096 122136 ?      Ssl  12:58   1:41 compiz
dmak1112  4425  0.1  1.5 852336 126496 ?       Sl   13:04   0:08 /opt/google/chrome/chrome --type=re
dmak1112  3420  0.9  2.3 932820 191284 ?       Sl   12:59   0:53 /opt/google/chrome/chrome --type=re
dmak1112  3270  1.4  2.3 1163332 193612 ?      Sl   12:59   1:25 /opt/google/chrome/chrome --type=gp
dmak1112  3166  5.3  2.9 1842800 241428 ?      SLl  12:59   5:10 /opt/google/chrome/chrome
dmak1112  3433  4.8  4.2 1095344 339992 ?      Sl   12:59   4:36 /opt/google/chrome/chrome --type=re
dmak1112  4322  0.4  5.1 1268008 419064 ?      Sl   13:03   0:27 /opt/google/chrome/chrome --type=re
mysql     1075  0.0 10.4 1899544 848092 ?      Ssl  12:58   0:03 /usr/sbin/mysqld

Is there any way I can get rid of some of the columns? I only want that User, pid, %mem and command.

Thanks!


Solution

  • aux is not actually a secret password to make ps let you in. It's a set of options specifying which processes (a and x) and fields (u) you want.

    man ps describes those and other options you can use. In your case:

    ps -eo user,pid,%mem,command --sort=%mem