Using ps sort by memory

The ps command in Linux can tell us all sorts of information about the running processes on our system. The command also reports memory usage for each running process. In this tutorial, you’ll see how to list processes on Linux, sorted by their memory consumption.

In this tutorial you will learn:

  • How to use ps command to sort by memory usage
  • How to sort by RAM, VSZ, and RSS columns
ps sort by memory
ps sort by memory
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software ps
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

ps sort by memory




The default output of a ps command is sorted by the process number by default. However, this default behavior can be changed with the use of --sort or k options.

Default output:

$ ps aux
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
[...]
root         366  0.0  0.0      0     0 ?        I<   Sep20   0:00 [cryptd]
systemd+     568  0.0  0.6  23904 13120 ?        Ss   Sep20   0:00 /lib/systemd/systemd-resolved
systemd+     569  0.0  0.2  90260  5968 ?        Ssl  Sep20   0:00 /lib/systemd/systemd-timesyncd
root         598  0.0  0.3 238172  7168 ?        Ssl  Sep20   0:00 /usr/lib/accountsservice/accounts-daemon
root         599  0.0  0.0   2548   772 ?        Ss   Sep20   0:00 /usr/sbin/acpid
avahi        602  0.0  0.1   8532  3300 ?        Ss   Sep20   0:00 avahi-daemon: running [linuxconfig.local]
[...]
Default output of ps command (unsorted)
Default output of ps command (unsorted)

Sort by %MEM

Sort by RAM percent usage. Highest values first:

$ ps aux --sort=-%mem
or
$ ps auxk-%mem
Sorting ps output by memory usage
Sorting ps output by memory usage

Sort by RSS or VSZ




The RSS and VSZ columns also report RAM usage, though its not as straightforward as the %MEM column. See our guide on RSS vs VSZ to learn the differences between the two types.

The syntax is the same as above. Just specify which column you’d like to sort by.

Sort by RSS usage. Highest values first:

$ ps aux --sort=-rss
or
$ ps auxk-rss

Sort by RSS usage. Highest values last:

$ ps aux --sort=+rss
or
$ ps auxk+rss
Sorting ps output by RSS values
Sorting ps output by RSS values

Please note that the + can be omitted as it is a default option and thus making ps auxkrss and ps auxk+rss identical.

Closing Thoughts




In this tutorial, we learned how to use the ps command to sort by memory usage. This is one of the quickest ways to see which processes are consuming most of your RAM, and gives us an in-depth view with the the RSS and VSZ columns. There are many other ways you can monitor RAM usage on Linux. Check out our guide on how to monitor RAM usage on Linux to see some other handy commands to do the job.