Top is a very powerful command to periodically display a sorted list of system processes. The default sorting key is %CPU on Linux. Below we collect 3 ways to sort processes by memory.
3 Ways to Sort by Memory in Top Command
press shift+m after running the top command
sort mem usage per process in the interactive menu. More details below.
run command top -o +%mem
Sort By memory Usage per-process in the interactive menu
press Shift+f to enter the interactive menu
press the up or down arrow until the %MEM choice is highlighted
press s to select %MEM choice
press enter to save your selection
press q to exit the interactive menu