Sometimes it is not comfortable to see meminfo in kilobytes when you have several gigs of RAM. In Linux, it looks like:
And here is how it looks in Mac OS X:
Is there a way to display meminfo in Linux top in terabytes, gigabytes and megabytes?
Stack Exchange network consists of 181 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.Visit Stack Exchange
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
When in top, typing capital "E" cycles through different memory units (KiB, MiB, GiB, etc., which are different from kB, MB and GB) in the total memory info:
While lower-case "e" does the same individual process lines:
From the manpage:
2c. MEMORY Usage This portion consists of two lines which may express values in kibibytes (KiB) through exbibytes (EiB) depending on the scaling factor enforced with the 'E' interactive command.
procps-ng version 3.3.9
System: CentOS 7
There is a command-line option which does that:
-M : Detect memory units Show memory units (k/M/G) and display floating point values in the memory summary.
So it is sufficient to run top like that:
-M does not work you can press
E while already in top.
man top (procps-ng version 3.3.9):
E :Extend-Memory-Scale in Summary Area With this command you can cycle through the available summary area memory scaling which ranges from KiB (kibibytes or 1,024 bytes) through EiB (exbibytes or 1,152,921,504,606,846,976 bytes).
If you see a '+' between a displayed number and the following label, it means that top was forced to truncate some portion of that number. By raising the scaling factor, such truncation can be avoided.
You can also use
htop. It's much cooler than
If you are using Debian or one of its derivatives, then you can install it using
sudo apt-get install htop.
Edit: Here is a screenshot with a better color scheme:
htoplooks better with either a white or a black background. Your screenshot color scheme is less than optimal.
F2. Nov 28, 2016 at 20:09
alias top='htop --no-color'so I can type 'top' and get a reasonable replacement for top without the horrible color scheme. Jul 12, 2019 at 18:18
top -M doesn't work on any of the Fedora, Debian or Ubuntu distros to my knowledge. I just tried it and it's not in the
procps-ng package that provides
top. There are many implementations of
top so one needs to pay special attention to which they use.
In general it's best to use
free with switching to get the amount of memory free on Linux.
You might have noticed that on CentOS 5 & 6 as well as RHEL 5 & 6 that
top -M appears to work. This is because those distros ship with the original version of
procps. The project was forked and there is now another project
Some of the details as to why there was a fork, from the Fedora Project's page.
Old (legacy) procps tools had no updates for several years and that led to a massive code split caused by a local-only application of distribution specific patches, which were not merged upstream. The project became hardly maintainable since some of the newly written patches were incompatible with sources maintained by other distributors. A similar incompatibility could be noticed in the applications behavior and their command line switches. This inevitable update can be understood as an effort to unify the procps tools across all Linux distributions.
So to be clear, the forked project,
procps-ng is what Debian, Fedora, Ubuntu, and other distros are using, the legacy project, which does support
top -M is still in use of several of the longer term releases that don't keep up with the latest and greatest.
NOTE: I downloaded the latest version of
procps-ng, "procps-ng version 188.8.131.52-14ef" and it too was lacking the
$ ./top/top -version procps-ng version 184.108.40.206-14ef Usage: lt-top -hv | -bcHiOSs -d secs -n max -u|U user -p pid(s) -o field -w [cols]
free with switches, you can see the most likely reason as to why the lack of units feature is missing from
procps-ng's implementation of
$ free -m total used free shared buffers cached Mem: 7782 6506 1276 0 504 1726 -/+ buffers/cache: 4274 3507 Swap: 7823 1429 6394 [saml@greeneggs ~]$ free -k total used free shared buffers cached Mem: 7969492 6663180 1306312 0 516948 1764780 -/+ buffers/cache: 4381452 3588040 Swap: 8011772 1463456 6548316
Rounding becomes problematic, so I believe,
procps's implementation avoids the issue by not offering the ability.
Does an OK job of showing aggregate memory usage.
In my opinion a better tool for looking at memory.
Another useful tool is
nmon for looking at system performance.
top -Mworks for me in RHEL6 Dec 19, 2013 at 21:58
-Mswitch, CentOS 5.8, also has this switch, "procps version 3.2.7". However Fedora 19 has "procps-ng version 3.3.8" which doesn't support the
-Mswitch. Dec 19, 2013 at 22:07
You can press the following keys:
You can use the command line option
E to specify the memory scaling, for example in gigabytes:
$ top -E g
-E :Extend-Memory-Scaling as: -E k | m | g | t | p | e Instructs top to force summary area memory to be scaled as: k - kibibytes m - mebibytes g - gibibytes t - tebibytes p - pebibytes e - exbibytes Later this can be changed with the `E' command toggle.
-e option can be used with the same options to change the values in the task list.
OS: Ubuntu 20.04 and RHEL 9
topto save your current settings as defaults. So start up with, e.g.
top -Eg -eg -o%MEMand press W. Next time you can just run
topwith settings saved.
So the quick answer : depending on your linux distro, try either :
OR, after starting top, type capital E (then W to write the config).
One of those should work for nearly everybody (except Solaris, of course, where you'd be lucky to have top at all).
bonus tip : every time you start a top instance on a new install, type ExyzW to save colours and highlighting and units - what a relief!
On RHEL7 top shift + e or CspsLK ON. You need " E " capital alphabet.
You will get in MiB, Gib, TiB, PiB, EiB. All these you can access.
And also you can you htop command which should be downlaoded and installed on rpm base system.
Thank you. Sagar Dalvi
Let's do some magic one liners so that you can alias what you want and never need to remember which letter to hit when in top to get what you want.
The want is to display top like output but having RSS in MBs and I'm adding also a desire to filter out only the program I want.
In the following examples we will use
python as the target processes we want to watch. We will, of course, use
perl to do that ;)
a. Without headers (if you memorized
ps auxc | grep python | perl -plae '$F=sprintf q[%0.3fMB],$F/2**10; $_=qq[@F]' | column -t
watch to emulate top, refreshing every 0.5 sec
watch -n 0.5 $'ps auxc | grep python | perl -plae \'$F=sprintf q[%0.3fMB],$F/2**10; $_=qq[@F]\' | column -t'
Make an alias (bash 4.4 or higher)
alias watch-python=$'watch -n 0.5 \'ps auxc | grep python | perl -plae "\$F=sprintf q[%0.3fMB],\$F/2**10; \$_=qq[@F]" | column -t | grep python\''
b. With headers (for the rest of us):
(ps auxc | head -1; ps auxc | grep python | perl -plae '$F=sprintf q[%0.3fMB],$F/2**10; $_=qq[@F]') | column -t
watch to emulate top, refreshing every 0.5 sec:
watch -n 0.5 $'(ps auxc | head -1; ps auxc | grep python | perl -plae \'$F=sprintf q[%0.3fMB],$F/2**10; $_=qq[@F]\') | column -t'
Make an alias (bash 4.4 or higher)
alias watch-python=$'watch -n 0.5 \'(ps auxc | head -1; ps auxc | grep python | perl -plae "\$F=sprintf q[%0.3fMB],\$F/2**10; \$_=qq[@F]") | column -t\''
| grep pythonif you want all processes
GBif you want GBs instead of MBs
pythonwith another string that your program starts with. You can inspect the output of
ps auxcto see what's the 10th (0-indexed) column says in case you get no output. a python program could be running with the name of the python script and not python itself for example, so make sure to use the name of the script instead.
%0.2fif you want only 2 decimals for MBs
watch -n 0.5with
watch -n 3if you want to refresh every 3 seconds
psflags in these examples the count of columns may change and the scripts may break.
top -Mto display the usage in MB. If you only want to monitor the memory usage, you can use rather use
htop. Not sure of any other option.
free -m, or better
Euntil it shows the memory cumulative you're looking for, then hit
Wto write that configuration to disk.