When we work on Linux, we want to know why our computer lags and is slow.
One of the reasons is filling up of the RAM of our machine.
How do we get to know what is the status of our RAM?
So we’ll use the free
command in Linux to check RAM in Ubuntu.
Check RAM in Ubuntu:
free

The command will display the results in bytes. The info in the different columns that we get are as follows:
total: Total memory installed in your system
used: Used memory
free: Unused memory
shared: Memory used (mostly) by temporary file system
buff/cache: Memory used by kernel buffers/Memory used by the page cache and slabs
available: Estimation of how much memory is available for starting new applications, without swapping.
How to check for free RAM in Linux
free -h
The parameters are as follows:
h: Human readable format

This will give you data in a Human readable format.
Note:
TheM
here denotes MebiBytes (power of 1024) and not Megabytes (power of 1000)
And theG
denotes Gibibytes (power of 1024) and not Gigabytes (power of 1000)
How to check for free RAM in Linux in SI Units
If you wish to get info in SI Unit of measure, eg. Kilo/Mega/Giga bytes. Use the below command.
free -h --si
The parameters are as follows:
h: Human readable format
si: SI Units, show kilo, mega, giga etc (power of 1000) instead of kibi, mebi, gibi (power of 1024).

This will give you data in a Human readable format in SI units.
Note:
We are using the SI Unit of measure in this command, so,
TheM
here denotes Megabytes (power of 1000) and not MebiBytes (power of 1024)
And theG
denotes Gigabytes (power of 1000) and not Gibibytes (power of 1024)
How to get the total of each of the used and free RAM on your Linux machine
An extra row will be displayed showing the total of the columns listed in the free
command in a human readable format.
free -th
The parameters are as follows:
t: Print total of all columns
h: Human readable format

How to know how much RAM is used for Buffers and Cache separately in a Human readable format
free -wh
The parameters are as follows:
w: Wide format
h: Human readable format

This will differentiate the RAM used for Buffers and Cache in a separate column
How to display the results of RAM usage at a specific interval
free -hw -s 2 -c 3
This will print the data in the following format:
h: Human readable format
w: Wide format (Buffers and Cache in different columns)
s: Print at every interval of seconds (Here: 2 seconds)
c: Print these many number (count) of times (Here: 3 times)

Hope you had a fruitful time reading this blog post.
I’ll see you again, until then, take care, be good and do good! 🙂