Using free command in Linux


Sometimes you may want to know the amount of free memory on your Linux system. Linux provides various memory information tools, free command is one of them. Using the free command will display the total amount, used, free, shared, buff/cache, and available physical and swap memory on a system.

In this article, we will discuss the usage of free command in Linux with some examples.

How to use the free command in Linux

The syntax of how to use the free command in a Linux system is given below –

free [options]

Where you can find a detailed list of options on its manual page.

Example of using the free command in Linux

Execute the following command to view free or used memory on your system –

free

You can see the output in the given image –

Where,

total – This shows the total amount of memory (physical and swap) in a system

used – It displays the amount of memory used by the system

free – This shows the free or unused memory of a system

shared – The memory used (mostly) by tmpfs

buff/cache – This shows the sum of buffer and cache. Buffer is the memory used by kernel buffers and the cache is the memory used by page cache and slabs

available – This is the estimation of how much memory available for starting a new application without swapping.

How to display the output in a human-readable format

Using option -h with free command will display the output in a human-readable format i.e. the memory will be displayed in units such as MB, GB, etc. Now use the following to display the output in human-readable format –

free -h

See the output below –

Display continuous result with certain delay

This can be very helpful if you are monitoring the memory usage of a system. Using option -s with free command will produce results after a given period of time.

Execute the following command to produce the result after 1.5 seconds –

free -s 1.5

Now see the output of this command –

Displaying results in megabytes or gigabytes

You can use the option -m to display the result in megabytes or -g to display the result in gigabytes. It also provides many other options to display the result in kilobytes, terabytes, petabytes, etc.

Now use the following command to display the result in megabytes –

free -m

Similarly, you can use the option -g to display the result in gigabytes.

For more information on options that are available to use with the command is given its man page. Execute the following command to view the manpage –

man free

Conclusion

This is how you can use the free command to see the statistics of memory usage in Linux. If you have any query then leave them in the comments below.

Leave a Comment

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