check free ram in linux

How to Check RAM Size in Linux

Many times you may need to check RAM size in Linux, especially if you are a system administrator. There are several ways to measure RAM size as well as get free RAM in Linux. In this article, we will look at how to check RAM size in Linux.

How to Check RAM Size in Linux

Here are the different ways to check RAM Size in Linux.

1. Using free command

This is the most common way to find out free RAM space available in your system.

$ free

It provides total amount of free and used physical and swap space, as well as kernel buffers. When you don’t use any option, it provides the following information.

  1. total – displays the total installed memory
  2. used – displays the used memory
  3. free – displays the unused memory
  4. shared – displays the memory used by tmpfs
  5. buffers – displays the memory used by kernel buffers
  6. cached – displays the memory used by the page cache and slabs
  7. buffers/cache – displays the sum of buffers and cache

There are several options available in free command. Here are the commonly used ones.

  • -b, – -bytes : displays the memory in bytes.
  • -k, – -kilo : displays the amount of memory in kilobytes(default).
  • -m, – -mega : displays the amount of memory in megabytes.
  • -g, – -giga : displays the amount of memory in gigabytes.
  • -h, – -human : Shows all output in human readable form such as in B(bytes), K(kilos), M(megas), G(gigas), and T(teras).
  • -t, – -total : Adds an additional line in the output showing the column totals.

2. Using /proc/meminfo

Free command basically reads information from /proc/meminfo file which contains more exhaustive system details. You can directly view this file using less or cat command.

$ cat /proc/meminfo
$ less /proc/meminfo

You will see the following kind of output.

MemTotal:      8277444 kB
MemFree:       1328304 kB
Buffers:        343152 kB
Cached:        2341132 kB
SwapCached:          0 kB
Active:        5450532 kB
Inactive:       973832 kB
HighTotal:           0 kB
HighFree:            0 kB
LowTotal:      8277444 kB
LowFree:       1328304 kB
SwapTotal:     1052248 kB
SwapFree:      1052248 kB
Hugepagesize:     2048 kB

If you want to view specific parameters from /proc/meminfo, you can do so using grep command. Here is a grep command to fetch details about MemTotal & MemFree

$ grep MemTotal /proc/meminfo
$ egrep 'MemTotal|MemFree' /proc/meminfo

3. Using vmstat command

You can also use vmstat command to view stats about system memory. It also shows additional information such as processes, paging, block IO, traps, and cpu activity. To view memory-related information, run the command with -s option.

$ vmstat -s

4. Using top command

You can also run the top command to get a dynamic view of processes running on your system, memory usage and free memory.

$ top

You can alternatively use htop or atop commands to get information related to process/memory.

The key difference between top and the previous commands is that top displays dynamic information about processes & memory, that updates constantly, while other commands give you a static information available at the point of running the commands.

In this article, we have learnt how to measure the total as well as free RAM size in Linux. You can use these commands on all Linux distributions since they are universally available. If you want to regularly check RAM size, you can add these commands into a shell script or cron job and run it periodically.

For example, you can simply open crontab with the following command:

crontab -e

and add the following line to fetch total and free memory space on your system, every day at 10.a.m. and write it to /home/mem.txt

* 10 * * * egrep 'MemTotal|MemFree|MemAvailable' /proc/meminfo >/home/mem.txt

Save and close the file to create the new cron job. Now you can just open /home/mem.txt file to view the free memory on that day.

Also read:

How to Disable SELinux in CentOS
MySQL Row Number & Its Uses
How to Comment Multiple Lines in MySQL
How to Install Mumble Server in Linux
How to Reboot Linux Server from Putty

Leave a Reply

Your email address will not be published. Required fields are marked *