Skip to main content

Commands

Free Command in Ubuntu

The free command lets you see your Ubuntu system's current RAM usage. Learn how to use the free command.

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:

free [options]

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:

free command without any options

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:

free -h
get human readable output in 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
💡
A better option here is to combine watch and free like this: watch freeThis 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 -t flag:

free -t

To make the output more human-readable, here, I will be combining the -t flag with the -h flag:

show the total amount of memory using the free command

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:

free --mega
find available system memory in megabytes using 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:

Understanding the man pages in Linux
Though extremely useful, man pages in Linux can be daunting and intimidating at first. This article aims to make it a bit easier to peruse manuals and quickly get the help one needs.

I hope you will find this guide helpful. And if you have any queries, feel free to ask in the comments.