10 ways to check the memory usage with “free” in Linux.


In this article, learn 10 ways to check the memory usage with free command in Linux. With the help of free command, we can check the memory usage of any Desktop or a Server.

free commands are the default command in the Linux OS. Used to check the current usage, swap space, total memory, the available memory, etc.

There are many other commands to check memory usage like atop, top, htop and vmstat. You can find the link “6 different commands to Check the Memory Usage in Linux”.

So we have divided the article into two sections,

  1. free command Output Explained in detail.
  2. 10 options to check the memory usage in Linux.

free command Output explained in detail.

free command in Linux to check the usage of memory in human readable format.

By using the above command, we can see the output in a human-readable format.

Now let’s discuss the Output parameters below,

total: The total RAM or Memory there in our Server.
used: The RAM or Memory used by your Applications.
free: The RAM or Memory that is not used by our Server.
shared: The RAM or Memory that is used by tmpfs. tmpfs is a file system that keeps the files in the virtual Memory.
buff/cache: This is the sum of buffer memory and cache memory.
available: How much RAM or Memory is available to start the new application.

10 options to check the memory usage with free command in Linux.

Let’s see the 10 ways or a 10 options to use free command in Linux.

1. How to check the memory usage in human-readable format

$ free -h
output:
     total  used  free  shared  buff/cache available
Mem:  19G   2.6G   12G   454M     4.5G       15G
Swap: 3.8G   0B    3.8G

So while using the -h option, the output is in a human-readable formation, which can be understandable to us.


2. How to print the memory usage for 3 seconds.

$ free -c 3

Let’s suppose we have to track the memory usage for 10 seconds, so use -c 10 with the free command.

So by using the -c option we can set the count or how many times we want to output. On the above command, there is -c 3, it will display output 3 times in 3 seconds.

Let’s suppose we have to track the memory usage for 10 seconds, so use -c 10 with the free command.

$ free -c 10


3. How to check the memory usage every 2 seconds in Linux.

So when we are using the -s option, it will repeat that print every N seconds.

$ free -s 2

Now we will get the output every 2 seconds. What to do if you want to repeat the output every 10 seconds.

$ free -s 10

4. How to check the memory usage every 2 seconds till 10 count.

Now if we have to print the usage every 2 seconds then use the -s option. And till count 10 use the -c option.

$ free -s 2 -c 10

The difference between kibibytes and kilobytes, and the same applies to the MiB and MB, GiB and GB… so on.

1. The kiB, MiB, GiB, and so on are the Binary systems.

2. The KB, MB, GB, and so on are the Decimal systems.


5. Use of -k option to check the memory usage in kibibytes.

$ free -k
output:
     total    used    free      shared  buff/cache available
Mem: 20234892 3487516 13135104  662132  3612272    15722108
Swap:3999740    0     3999740

This is the default value set in the free command, If you just use the free command you get the same output.


6. use –kilo option to check in kibibytes.

$ free --kilo
output:
     total    used    free     shared  buff/cache available
Mem: 20720529 2603667 15539732 466477  2577129    17312907
Swap:4095733    0     4095733

7. use -m option to check in mebibytes.

$ free -m 
output:
     total used free  shared  buff/cache  available
Mem: 19760 2503 14051   430      3205      16467
Swap:3905   0   3905

8. use –mega option to check in megabytes.

$ free --mega  
output:
     total used free   shared  buff/cache  available
Mem: 20234 2598 12830   445       4806       16823
Swap:3999   0   3999

9. use -g option to check in gibibytes.

$ free -g 
output:
     total used free shared buff/cache available
Mem: 19     2    12    0        4          15
Swap: 3     0     3

10. use -giga option to check in gigabytes.

$ free --giga
output:
     total used free shared buff/cache available
Mem:  20    2    12     0       4        16
Swap: 3     0    3

free command cheat sheet
1. How to check RAM size in kibibytes.

Example:
#free -k
2. How to check RAM size in kilobytes.

Example:
#free --kilo
3. How to check RAM size in mebibytes.

Example:
#free -m
4. How to check RAM size in megabytes.

Example:
#free --mega
5. How to check RAM size in gibibytes.

Example:
#free -g
6. How to check RAM size in gigabytes.

Example:
#free --giga
7. How to check RAM size in human readable format.

Example:
#free -h
8. How to check RAM size in terabytes and petabytes.

Example:
#free --tera  //for terabytes
#free --peta //for petabytes
9. How to check RAM utlization in every seconds

Example:
#free -s 1
10. How to check RAM utlization in every 5 seconds till 10 count

Example:
#free -s 5 -c 10

Thank you so much to read this article, you can refer to more basic commands. Source code for free command.

Give your valuable time