As the name suggests, the free command is used to get information about the free system memory in Linux.
So in this guide, I will walk you through multiple examples of how you can use the free command.
How to use the free command in Ubuntu
So let's start with the syntax of the free command.
Here's the syntax that you'd have to follow to use the free command:
Pretty simple compared to other commands. Isn't it?
And when used without any options, the free command will show the output in kilobytes and look like this:
In my opinion, the default output is confusing. But don't worry, there are various options by which you can tweak the output and make it much more readable.
So let's start with the examples part.
1. Get output in human-readable form
As I mentioned, the free command gets the output in kilobytes which is not the most desired way to check the system memory.
To get the output in human-readable form, you'd have to use the
-h option with the free command:
2. Get the live memory statistics
Like htop, the free utility can also be used to get live statistics. To do so, the free command can be tweaked to refresh itself after certain intervals.
And for that purpose, you'd have to use the
-s flag followed by the time (in seconds) you want to refresh the stats:
free -s [time]
So let's say I want to refresh the memory stats after every 2 seconds, then, I will be using the following command:
free -s 2
This will constantly refresh the free command output but without cluttering the screen.
3. Show the total amount of memory
You may want to find out the total amount of memory (addition of RAM + swap) and in that case, you can use the
To make the output more human-readable, here, I will be combining the
-t flag with the
4. Get the output in Megabytes
You may want to get the output in megabytes and in those times, you'd have to use the
--mega option with the free command:
Want to get the most out of CLI tools? Learn how to use the man page
In case you don't know, the man page is the most detailed documentation of each command line utility available in Linux.
And if you don't know how to use it, you are missing out on a lot of potentials.
So we made a dedicated tutorial on how you can use the man page on Linux:
I hope you will find this guide helpful. And if you have any queries, feel free to ask in the comments.