Using the free Command on Linux

In this tutorial, you will be learning how to use the free command on your Linux operating system.

free command on linux

You can use the free command to give you a quick insight into your system’s memory usage. The information it provides is significantly more straightforward to digest than other tools such as the top command.

Using this tool will give you the status of both your system’s physical memory and its virtual swap memory. This includes information on the total amount of memory available, used, free, shared, and more.

This tool works by parsing the information provided from the file located at “/proc/meminfo” and showing it in a human-readable format. You can even view this data yourself by using the cat command on the file.

Below, we will go through several ways to use this free command to see the status of your system’s memory.

Table of Contents

Syntax of the free Command

The syntax for the free command is very straightforward as it only has a single optional parameter.

Below you can see the basic syntax of the free command.

free [OPTIONS]

By using the “[OPTIONS]” parameter, you can control the behavior of the free command. Most options for this tool revolve around changing how the data is displayed to you.

You can also use the option to allow “free” to continue to update the values it’s displaying.

Basic Usage of the free Command

Now that you know the syntax of the free command let us explore using the tool without passing in any options.

Using the command without an option will display the values it returns in kibibytes (KiB). A kibibyte is equal to 1024 bytes, unlike a kilobyte that equals 1000 bytes.

free

After running this command on your Linux system, you will end up with the following data in the command line.

pi@pimylifeup:~ $ free
               total        used        free      shared  buff/cache   available
Mem:         3930860      225652     3131416       88592      573792     3483164
Swap:         102396           0      102396

Breakdown of the Data Provided by free

Below we will go into this data and explain what all of it means to you as the end-user.

Row Labels

From the results of the free command, you will notice there are two rows of data. These two rows are labeled “Mem” and “Swap“.

  • Mem – The data shown here represents the physical memory of your system.
  • Swap – Values that are shown in this row reflect swap memory usage on your system. Swap is what Linux will use when your system runs out of physical memory. It does this to try and prevent out of memory (OOM) errors.

Column Labels

Next, six different columns are displayed by default. We will quickly go through what each of these columns is used for.

  • total – This value indicates to you the total amount of physical memory available on your system.

    Any application running on your system can utilize this memory.
  • used – The total amount of memory that is currently being consumed by your operating system.

    This value is calculated by taking the “total” and subtracting the “free“, “buffers“, and “cache” values.
  • free – This value represents the unused memory and is available for the system to use immediately.
  • shared – The value shown here is the memory that the tmpfs file system has consumed.
  • buff/cache – This value is the combined value of the memory consumed by “buffers” and the “cache“.

    The system can attempt to reclaim this memory immediately if required.
    • buffers – Memory that the kernel buffers have consumed.
    • cache – Memory consumed by the page cache and slabs.
  • available – The amount of memory that the system can utilize without Linux beginning to use the swap memory.

Displaying Memory Usage in a Human Readable Format

One of the first things you would have noticed after using the free command on Linux is that the values aren’t shown in an easily readable format. Instead, these values are represented in kibibytes.

However, thanks to the “-h” option, we can tell the “free” command to print values in a human-readable format.

This tool achieves this by converting the values into “bytes” (B), “kilobytes” (Ki), “megabytes” (Mi), or “gigabytes” (Gi).

free -h

After running this command on your system, you will see the following data on your device.

pi@pimylifeup:~ $ free -h
               total        used        free      shared  buff/cache   available
Mem:           3.7Gi       220Mi       3.0Gi        86Mi       560Mi       3.3Gi
Swap:           99Mi          0B        99Mi

You can see that the values have been greatly simplified, and the values can be quickly read without having to perform any conversions.

Changing the Memory Usage Metrics From the free Command

The free command will return its value in “kibibytes” by default. A kibibyte is equivalent to 1024 bytes.

The functionality of the free command allows you to modify the metrics returned by this utility. There are several options that you can use to do this, each one setting a different metric.

Below you can check our table to see the various options that you can utilize. These options are what let you control the values displayed by the command.

OptionValueDescriptionOptionValueDescription
-b, --bytes1bytes
-k, --kibi1024kibibytes – Default--kilo1000kilobytes
-m, --mebi10242mebibytes--mega10002megabytes
-g, --gibi10243gibibytes--giga10003gigabytes
--tebi10244tebibytes--tera10004terabytes
--pebi10245pebibytes--peta10005petabytes

For example, if we wanted to show the data from the free command in megabytes, we would use the “--mega” options.

free --mega

Below you can see the values that using this option would produce. All values have been converted from the default “kibibytes” to “megabytes“.

pi@pimylifeup:~ $ free --mega
               total        used        free      shared  buff/cache   available
Mem:            4025         230        3204          90         589        3566
Swap:            104           0         104

Displaying the Total Column Values

The free command on Linux allows you to display the total column values. To achieve this, all you need to do is use the “-t” option.

Using this option will add a row that displays the total values of the “total“, “used” and “free” columns. This is useful if you want to quickly see how much of your physical and swap memory is being consumed.

free -t

Below you can see an example of the result this command would produce. You can now see the total values easily.

pi@pimylifeup:~ $ free -t
               total        used        free      shared  buff/cache   available
Mem:         3930860      225776     3129072       88592      576012     3483004
Swap:         102396           0      102396
Total:       4033256      225776     3231468

Display High and Low Memory Statistics

An additional function of the free command is that it can also retrieve your Linux system’s high and low memory statistics.

Using this, you can see the low and high usages of your physical memory for the “total“, “used“, and “free” columns.

You can achieve this by using the “-l” or “--lohi” option alongside the “free” command.

free -l

We have included an example of what using this option would look like.

pi@pimylifeup:~ $ free -l
               total        used        free      shared  buff/cache   available
Mem:         3930860      225808     3128988       88592      576064     3482980
Low:          666348      176660      489688
High:        3264512      625212     2639300
Swap:         102396           0      102396

Use the Wide Output Mode with the free Command

By default, when using the free command on Linux, the utility combines the values of the “buffer” and “cache“.

You can separate these two values into their own columns using the “-w” or “--wide” option. This option is useful if you want to see how much memory is consumed by either resource.

free -w

After running this command, you will end up with a result, as shown below. The buffers and cache values are now separated into their own columns.

pi@pimylifeup:~ $ free -w
               total        used        free      shared     buffers       cache   available
Mem:         3930860      225688     3129068       88592       70424      505680     3483100
Swap:         102396           0      102396

Repeating the Output from the free Command

The free command also allows you to repeat its output continuously to get updated values.

There are two options to control the update process that you can use. These options work best when they are used together.

  • -s N or --seconds N – Using this option, you can tell the free command to update its results after the specified amount of seconds has passed.

    For example, if you wanted the results to be updated every 3 seconds, you would use “-s 3” or “--seconds 3“.
  • -c N or --count N – You can use this option to control how many times the free command should run before it exits.

    For example, if we only want the command to run twice before quitting, we can use “-c 2” or “--count 2“.

Example of Updating the Result Continuously

For this example, we will update the free command results every 5 seconds.

Using the “--seconds” option without the “--count” option, the command will continue to run until the process is killed.

free --seconds 5

When you use the command like this, it will continue to update until it is stopped. To quit the program, you can press CTRL + C on your keyboard.

Example of Updating For a Specific Number of Times

If you only want to get the results a certain number of times, you can combine both the the “--seconds” and “--count” options.

For this example, we will update the results every 3 seconds but only perform the update twice. Since we want two updates, the count will need to be 3 as the initial call counts towards this number.

free --seconds 3 --count 3

After 6 seconds, you should have multiple updates from the free command, and the program will automatically quit.

An example of the data you would see using this command is the following.

pi@pimylifeup:~ $ free --seconds 3 --count 3
               total        used        free      shared  buff/cache   available
Mem:         3930860      225192     3129328       88592      576340     3483568
Swap:         102396           0      102396

               total        used        free      shared  buff/cache   available
Mem:         3930860      225200     3129320       88592      576340     3483560
Swap:         102396           0      102396

               total        used        free      shared  buff/cache   available
Mem:         3930860      225232     3129288       88592      576340     3483528
Swap:         102396           0      102396

Conclusion

Hopefully, by this point, you will have learned how to use the free command on your Linux system.

Throughout this guide, we have shown you several examples of how you can use this utility to monitor memory on your system.

Keeping track of your system’s memory usage is made simple thanks to this command. While it doesn’t provide in-depth information about individual programs’ memory usage, it provides a simplified overview.

If you have any questions about using the free command, please comment below.

Be sure to check out our numerous other Linux command guides or our general Linux tutorials.

Leave a Reply

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