Tag Archives: ubuntu physical memory

4 ways to check the size of physical memory (RAM) in Linux

An article explaining how to check physical memory (RAM) in the Linux server. 4 different commands to get memory information from the Linux server.

Checking physical memory (RAM)

In this article we will see basic commands to check physical memory on a server in Linux. Many beginners struggle with knowing their system well in context to resources like CPU, Memory, disks, etc. So I decided to write this small article pinpointing commands to check RAM on the Linux server. These commands will work in different flavors of Linux like Red Hat, CentOS, Suse, Ubuntu, Fedora, Debian, etc.

Without much delay lets dive into commands –

1. Using free command

The first command is free. This is the simplest command to check your physical memory. This command is mainly used for checking RAM and SWAP on the system. Using different switch you can change the byte-format of output. Like -b for bytes, -k for kilobytes, -m for megabytes and -g for gigabytes.

Check row with Mem: and number against it. That’s the physical RAM of your server.

root@kerneltalks # free -b
             total       used       free     shared    buffers     cached
Mem:    135208493056 1247084544 133961408512          0  175325184  191807488
-/+ buffers/cache:  879951872 134328541184
Swap:   17174347776          0 17174347776

root@kerneltalks # free -k
             total       used       free     shared    buffers     cached
Mem:     132039544    1218368  130821176          0     171216     187316
-/+ buffers/cache:     859836  131179708
Swap:     16771824          0   16771824

root@kerneltalks # free -m
             total       used       free     shared    buffers     cached
Mem:        128944       1189     127754          0        167        182
-/+ buffers/cache:        839     128105
Swap:        16378          0      16378

root@kerneltalks # free -g
             total       used       free     shared    buffers     cached
Mem:           125          1        124          0          0          0
-/+ buffers/cache:          0        125
Swap:           15          0         15

In the above output you can see the system is installed with 125GB of physical RAM (observe highlighted rows). By using a different switch -b, -k, -m and -g output changed numbers according to selected byte-format.

2. Using /proc/meminfo file

Another way is to read memory info from the proc filesystem. /proc/meminfo is the file you should read to get detailed information about memory. The very first line or line starts with MemTotal is your total physical memory on the server.

root@kerneltalks # cat /proc/meminfo |grep MemTotal
MemTotal:       132039544 kB

As you can see from output, memory is displayed in kilobytes.

3. Using top command

The famous top command also lists physical memory information in a very clear way. In the upper section of the top command output lies the CPU, Memory, and SWAP information.

root@kerneltalks # top
top - 16:03:41 up 89 days,  3:43,  1 user,  load average: 0.00, 0.01, 0.05
Tasks: 141 total,   1 running, 140 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  132039544k total,  1218336k used, 130821208k free,   171224k buffers
Swap: 16771824k total,        0k used, 16771824k free,   187420k cached

I clipped the above section of the top command output in the above example. Check second last line saying Mem: (highlighted row). This shows physical memory in kilobytes. You can see the total, used, and free portions of it. Total is your actual RAM installed on the server.

4. Using vmstat

Another way is to use vmstat (virtual memory stats) command with -s switch. This will list memory in detail with the first-line being total memory on the server.

# vmstat -s
    132039544  total memory
      1218692  used memory
       181732  active memory
----output trimmed----

Memory is displayed in kilobytes by default. The very first line shows you total memory on the server.