3 Ways To Check RAM Usage Via Linux Command Line

Here are 3 simple ways to check your systems current RAM usage, when working via command line.

The free command has multiple options. Free on its own will provide you the ram usage in bytes. This is probably useless to most so adding -m after it will give you the value in megabytes.

free -m

The output should be something like this

total used free shared buffers cached

             total       used       free     shared    buffers     cached
Mem:          4096        712       3383        131          0        307
-/+ buffers/cache:        405       3690
Swap:          128          0        128

An alternative is to use top. This will give you the specific applications that are using the memory along with CPU usage. The best thing about this command is it’s in real time. The data is very much like that displayed in task manager for Windows.

top

This should output something like this

PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
   1 root      20   0 19364  436  132 S  0.0  0.0   0:01.11 init
   2 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kthreadd/69576
   3 root      20   0     0    0    0 S  0.0  0.0   0:00.00 khelper/69576
   4 root      20   0     0    0    0 S  0.0  0.0   0:00.00 rpciod/69576/0
   5 root      20   0     0    0    0 S  0.0  0.0   0:00.00 rpciod/69576/1
   6 root      20   0     0    0    0 S  0.0  0.0   0:00.00 rpciod/69576/2
   7 root      20   0     0    0    0 S  0.0  0.0   0:00.00 rpciod/69576/3
   8 root      20   0     0    0    0 S  0.0  0.0   0:00.00 nfsiod/69576
 127 root      16  -4 10652  280    0 S  0.0  0.0   0:00.01 udevd
 499 root      20   0  179m 2256  324 S  0.0  0.1   0:10.23 rsyslogd
 545 named     20   0  307m  26m 1720 S  0.0  0.7   1:24.78 named
 563 root      20   0  4580  148   60 S  0.0  0.0   0:00.06 mdadm
 572 dbus      20   0 21436  236    4 S  0.0  0.0   0:00.00 dbus-daemon
 610 root      20   0 66220  900  192 S  0.0  0.0   0:07.61 sshd
 621 root      20   0 52112  628   88 S  0.0  0.0   0:00.28 vsftpd
 657 root      20   0  105m  304    4 S  0.0  0.0   0:00.05 mysqld_safe
 864 mysql     20   0 1727m 170m 3940 S  0.0  4.2  49:40.23 mysqld

vmstat is another simple way to check RAM usage. This isn’t quite as useful if you want to quicky check. It will display most of what the free command displays along with a few extra details.

vmstat -s

Output

4194304 total memory
728952 used memory
296176 active memory
383972 inactive memory
3465352 free memory
0 buffer memory
314504 swap cache
131072 total swap
0 used swap
131072 free swap
887837 non-nice user cpu ticks
1429 nice user cpu ticks
199846 system cpu ticks
182661931 idle cpu ticks
134832 IO-wait cpu ticks
0 IRQ cpu ticks
0 softirq cpu ticks
0 stolen cpu ticks
13589860 pages paged in
5739148 pages paged out
0 pages swapped in
0 pages swapped out
0 interrupts
46730701 CPU context switches
1423896862 boot time
105029 forks

While on the subject of RAM the following commands will give you the technical information about the RAM that is installed on the system you are working on. dmidecode will get you the max capacity, number of devices and some other basic information.

dmidecode -t 16
dmidecode -t 17

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.