Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I display the top results in my terminal in real time so that the list is sorted by memory usage?

share|improve this question
On Linux, > and < move the sort column right and left. Since the %MEM column is just right of the %CPU column, which is also the default sort column, it takes only one keystroke to switch between the two. I know, your question has the macintosh tag, that's why I'm writing this answer as a comment. – Walter Tross Sep 19 '15 at 18:37
I prefer htop, mainly because it tells me how to do this. – lindhe Jan 19 at 22:05

Use quick tip using top command in linux/unix


hit Shift + f, then choose the display to order by memory usage by hitting key n then press Enter. You will see active process ordered by memory usage.

Or you can just press M after running the top command.

On OS X 10.10 the command top -o MEM seems to work.



share|improve this answer
Does not work for me – jan Mar 5 '15 at 11:09
shift+m worked for me on linux – Nadine Aug 23 '15 at 12:31

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 VIRT, RES or SHR too. On a Macintosh I would probably use mem or vsize.

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.

share|improve this answer
The answer could user more clarity: %MEM is given as an answer to the eager reader; while it doesn't work everywhere (by far). – 7heo.tk May 6 '15 at 15:00
For Macbook 2014 this is saying: top -o %MEM invalid argument -o: %MEM – anon58192932 Jun 1 '15 at 17:43
I'm sorry to hear that. – ytg Jun 1 '15 at 20:03
This is the only answer that actually worked on centos for me. – Amalgovinus Mar 8 at 22:40
Thanks. Works on Ubuntu 16.04. – DmitryKanunnikoff Jul 20 at 9:11

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".

share|improve this answer

For Ubuntu 14.04 starting with

htop -s=MEM

did the trick for me.

share|improve this answer
Works well for OSX as well. – ehime May 2 at 18:16

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.

share|improve this answer

If top is already running, press o . Above the data, a prompt will appear:

primary key [xxxxx]:

Where 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".

share|improve this answer

Ubuntu 14.04 - this works just fine:

htop --sort-key=PERCENT_MEM
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.