How can I display the
top results in my terminal in real time so that the list is sorted by memory usage?
top command in Linux/Unix:
- press shift+m after running the
- or you can interactively choose which column to sort on
- press Shift+f to enter the interactive menu
- press the up or down arrow until the
%MEMchoice is highlighted
- press s to select
- press enter to save your selection
- press q to exit the interactive menu
Or specify the sort order on the command line
# on OS-X top -o MEM # other distros top -o %MEM
The command line option
-o (o standing for "Override-sort-field") also works on my Xubuntu machine and according to the Mac man page of top it should work on a Macintosh too. If I want to short by memory usage I usually use
top -o %MEM
which sorts by the column
%MEM. But I can use
SHR too. On a Macintosh I would probably use
I don't know why or how but this is pretty much different between Unix systems and even between Linux distributions. For example
-o isn't even available on my Raspberry running Wheezy. It may be worth give it a try though.
It seems like the -o flag will take the actual column name. So if the top command shows only "mem" then the command should be "top -o mem".
For the ubuntu machine I am testing with, the column is called "%MEM". On the OSX Yosemite I tried, it is "mem".
For Ubuntu 14.04 starting with
did the trick for me.
top is already running, press o . Above the data, a prompt will appear:
primary key [xxxxx]:
xxxxx is the current sorting key. Type the name of the column by which you want to sort. If a column name contains "%" or "#", omit the character. For %CPU, just type "cpu".
The original question seems to have been for a Mac, but for anyone else stumbling across this answer, on Red Hat Linux (and many others), 'top -m' starts top with results sorted by memory usage.
On linux, run:
Then press, Shift + M.
Ubuntu 14.04 - this works just fine:
If you're using the
top that comes with Ubuntu (
top -v =
procps-ng version 3.3.10), then you can use these interactive keyboard shortcuts to change the sorting. Note that these are all capital letters, so either use
By default, they will be sorted in DESC order. Use
R to toggle ASC/DESC.
To set the sorting from the command line option, use
top -o %MEM. You can specify any column.
protected by don_crissti Oct 24 '17 at 21:58
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?