I'd like to start top with sorting set to resident memory size, instead of the default CPU usage.

I don't see a way to do that from command line arguments or startup file. Obviously I can't echo "Oq" | top either since I'd prevent top from using the tty.

Is there a way to do this?

Update: I run top on Linux (recent Ubuntu and Debian, 3.x kernels), installed e.g. as 'procps 1:3.2.8-11ubun', though I suppose that the column ordering functionality might be pretty cross-platform.

  • What OS are you using? The details will likely depend on your top implementation. – terdon Nov 11 '14 at 15:41
  • Some more interesting read of varying behaviours of top is observed here. – Ramesh Nov 11 '14 at 16:05
  • @Ramesh: aha, Shift+W works with my version and saves the settings as default, restored at the next start! Please update your answer so that I could accept it :) – 9000 Nov 11 '14 at 16:13

top -M sorts by resident memory usage.

M sort tasks by resident memory usage.

This is the version of top on my system.

top -v top: procps version 3.2.7

If your Linux distribution supports the -M flag, you could use it as mentioned here.

However, if your top doesn't support the -M flag, you could launch your top command and get into the interactive mode by typing h to check the sort field. (I assume it is the same across various distributions)

In my system (rather the top version of my system), I could type F or O to select the sorting field and key Q of my top version lets me sort on resident memory.

If you want to save your configuration you could do something as mentioned by slm here.

Saving configuration

You can use the Shift+W to save your changes so they're the defaults:

  W         Write configuration file

The file is stored here, $HOME/.toprc, and looks like this:

$ more .toprc 
RCfile for "top with windows"       # shameless braggin'
Id:a, Mode_altscr=0, Mode_irixps=1, Delay_time=1.000, Curwin=2
Def fieldscur=AEHIoqTWKNMBcdfgjpLrsuvyzX
    winflags=129016, sortindx=19, maxtasks=0
    summclr=2, msgsclr=5, headclr=7, taskclr=7
Job fieldscur=ABcefgjlrstuvyzMKNHIWOPQDX
    winflags=63416, sortindx=13, maxtasks=0
    summclr=6, msgsclr=6, headclr=7, taskclr=6
Mem fieldscur=ANOPQRSTUVbcdefgjlmyzWHIKX
    winflags=65464, sortindx=13, maxtasks=0
    summclr=5, msgsclr=5, headclr=4, taskclr=5
Usr fieldscur=ABDECGfhijlopqrstuvyzMKNWX
    winflags=65464, sortindx=12, maxtasks=0
    summclr=3, msgsclr=3, headclr=2, taskclr=7

See section 5 of the man page for more details, "5. FILES".

| improve this answer | |
  • Hmm, my build of top does not seem to support it, though it reports version 3.2.8. – 9000 Nov 11 '14 at 15:51

On my linux system, top (procps-ng version 3.3.9) has an -o switch:

   -o  :Override-sort-field as:  -o fieldname
        Specifies  the  name  of  the  field  on  which tasks will be
        sorted, independent of what is reflected in the configuration
        file.  You can prepend a '+' or '-' to the field name to also
        override the sort direction.  A leading '+' will force  sort‐
        ing  high  to  low,  whereas  a '-' will ensure a low to high

So, top -o RES starts top sorted by resident memory size.

| improve this answer | |

You've got top -a on Linux. Try checking manpages on Unix its top -m. Not sure if we are talking about the same memory.

| improve this answer | |
  • FYI, there are differing versions of top on various Linux distros, so you might want to make your A more specific. – slm Nov 11 '14 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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