How to use free command in Linux - 4

I have covered some tutorials about command line Linux utility, like tar and df, but in this change I will cover the free command. So what is free ?free is a command line Linux utilities that use to check the total amount of free and used physical memory (or RAM) and show the swap space in your Linux/Unix System. free has variant options, for example if you want to display free memory in bytes, you can use option -b, for kilobytes use the option -k, for megabytes use the option -m, and for gigabytes you can use the option -g.

There are many options that you can use with free, So just like the titile say How to use free command in Linux ? Well, To use free you don’t need to install anything, because its default on all Linux distribtion, now lets we explore and practice this free Linux utility.

Open your favorite terminal and type the following commands :

$ free
How to use free command in Linux - 1

Do you see the information about your free memory ?. As you can see :
Line 1 : Shows your memory details like total available RAM, used RAM, Shared RAM, RAM Buffers, and RAM that used for caching content.
Line 2 : Shows total used buffers/cache used and free buffers/cache.
Line 3 : Shows total available Swap space available, used Swap space and free space for swap.

How to check the version ?

According to the manual to check version you can add the -V option after the free command.

$ free -V
How to use free command in Linux - 2
free -V

As you can see on the screenshot, the option -V will show you the information about the version.

Use different memory format

Now we know how to use free command, but with default display information its little bit hard to read, because its display the information in kilobytes, so to make it easier to read free has some options to display the information of your free memory in different format like megabytes or gigabytes. Because we all used to see free memory in megabytes format, so I will use the -m option.

$ free -m
How to use free command in Linux - 3
free -m

Now you see the information in megabytes, as you see on the screenshot my total ram is 4911 MB, used memory 2810 MB, and free memory 2100 MB, also you can try the different options like -b or -g to suit your needs.

Show detailed low and high memory statistics

To show the detailed memory statistics free provide the option -l, now lets try this option.

$ free -l
How to use free command in Linux - 4
free -l

As I mentioned before, it use to display the high and low memory statistics and you can see on the screenshot there is a line with high and low information.

Show updated result every # seconds

free also provide the feature for update the information about your memory statistics every seconds, to use this features use the option -s, once you run the command you will get fresh information from the utility every seconds. You can also combine it with the other options that I explained in this tutorial, such as the -m option. Well, lets try this option.

$ free -s 2

The above command will update the information every 2 seconds, you can change it to whatever you like, but if you get an error free : seconds argument ‘n’ failed (I don’t know what cause the error), you must use -c option to make it work. So it will be like this :

$ free -c count -s n

Change count to your desired count and to change the amount of every seconds the command show the information

How to use free command in Linux - 5
free -c 2 -s 2

There is also an alternative, you can use watch command to make it update the information , so the command will be like this :

$ watch -n 2 free -m

With the command above free will update every 2 seconds and show the format in megabytes.

How to use free command in Linux - 6
watch -n 2 free -m

That’s all for my post with title How to use free command in Linux ?, I hope this post can help you to solve your problem and improve your knowledge about Linux. Every comments and suggestion are very welcome, thank you !.

Leave a Reply

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