A2oz

How do you sort by memory in Linux top?

Published in Linux commands 2 mins read

You can sort the processes listed in the top command by memory usage using the following steps:

  1. Open the top command: Type top in your terminal and press Enter.
  2. Press Shift + M: This will sort the processes by their memory usage.

The processes will now be listed in descending order of their memory consumption, with the process using the most memory at the top.

Additional Information:

  • You can toggle between ascending and descending order by pressing Shift + M repeatedly.
  • You can use other keyboard shortcuts to sort by other criteria, such as CPU usage (Shift + P) or process ID (Shift + k).

Example:

Here's an example of how the top command might look after sorting by memory:

top - 15:00:05 up 1 day, 18:23,  1 user,  load average: 0.72, 0.65, 0.55
Tasks: 180 total,   1 running, 179 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.1 us,  0.1 sy,  0.0 ni, 99.7 id,  0.0 wa,  0.0 hi,  0.1 si,  0.0 st
MiB Mem :  15963.0 total,   6166.4 free,   6245.8 used,   3550.8 buff/cache
MiB Swap:  16384.0 total,       0.0 free,   16384.0 used.   4933.2 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
 3212 root      20   0 1507620 168800 11116 S   0.0 10.6   0:00.12 chrome
 1018 root      20   0 1060000 143040  9856 S   0.0  8.9   0:00.02 gnome-shell
  545 root      20   0 1151448 119444  7824 S   0.0  7.5   0:00.04 Xorg
 2746 root      20   0  605888  89212  5972 S   0.0  5.6   0:00.03 firefox
  852 root      20   0  823288  79840  5492 S   0.0  5.0   0:00.01 systemd-logind
 ...

In this example, the chrome process is using the most memory (10.6% of total memory).

Related Articles