Linux Basics: How To Use The ‘free’ Command In Linux

We have covered many useful linux utilities in our website and this time I will explain to you guys how to check the total amount of free and used physical memory and swap space in the system with the help of the free command-line utility. According to the manual page the free utility is used to display amount of free and used memory in the system as well as the buffers used by the kernel.

I really like and use this tool because it is very rich in options. For example I can use the option -b to display the amount of  memory in bytes, the option -g to display the amount of memory in gigabytes, the option –k to display the amount of memory in  kilobytes and -m to display  amount of memory in megabytes.

But it does not end here. There are many other options with different purposes. One of them is -l which can be used to show detailed low and high memory statistics.

Now lets explore the others and practise the free linux utility. Remember: If you want to be good at something you have to practise it, so for me to learn how to use new linux tools it is very important to practise them and see some action while using different tools by combining many different options.

By the way the free utility comes installed by default so you don’t have to install anything.

Open a new terminal tab and type the following command with the -V option. What do you see?

free -V

Do you see the information about the version of your utility. As you can see the option -V is used to display version information. I get the following output when running the above command.

procps version 3.2.8

Now try to experiment. Do not add any option to the free utility.Just run it! Are you curious to know what is going to do? So if you are just type free on your terminal tab and run it.

free

The follwing is the output I get.

 oltjano@baby:~$ free
 total      used free shared buffers cached
 Mem: 3929724 2969188 960536 0 105456 1111648
 -/+ buffers/cache: 1752084 2177640
 Swap: 0 0 0

As you linux nerds can see the free utility is giving me information on total available memory, used memory, cached memory, buffers and also free memory. Now try and combine the free utility with the -b option. I am going to run the free -b on my terminal and see what is going to happen.

free -b

Different results compared to the case when free is executed without any option will be printed on the screen.

 oltjano@baby:~$ free
 total          used      free   shared   buffers     cached
 Mem: 3929724 2969188 960536 0         105456    1111648
 -/+ buffers/cache: 1752084 2177640
 Swap: 0 0 0

Why does this happen?  It happens because the option -b tell the free commandline utility to display the amount of memory in bytes. Now that you are a bit familiar with the free utility and its usage try to run it combined with the option -l.

free -l

When I run the above command I get the following output.

 oltjano@baby:~$ free -l
 total            used           free     shared   buffers    cached
 Mem: 3929724     2985776     943948    0        107388    1150544
 Low:  3929724     2985776      943948
 High: 0 0 0
 -/+ buffers/cache: 1727844 2201880
 Swap: 0 0 0

As I mentioned earlier in this tutorial the option -l is used to  show detailed low and high memory statistics. Another useful and special option is the option -s which is used to continuously  display  the result delay seconds apart.

For example the following command will help you to get updated results from the free utility every 3 seconds.

free -s 3

Once you run the above command on your terminal you will get fresh information from the free utlity every three seconds. You can also use other options that I explained in this tutorial such as the option -m  to display the amount of memory in megabytes, the -g option to display the amount of memory in gigabytes etc.

Feel free to experiment with the linux free utility. It is not going to hurt your system!