The free Command in Linux – The Practical Reference

The free command is a very compact yet incredible utility in Linux which must be in the arsenal of any computer geek. This command deals with the system’s memory statistics. These statistics come in handy when we wish to know whether we can run more applications in our system.

Let us quickly move onto the details of the free command.

1. Basic Output of the free Command

If we simply type free on the Linux terminal, we will get a total of three lines of output.

Free Command Basic Output
Basic Output of free command

The explanation is as follows:

  • Mem – The information related to Physical Memory (RAM) in the system.
    • total – The total amount of RAM installed on the computer.
    • used – The amount of RAM currently being used by applications.
    • free – The amount of RAM absolutely free to use.
    • shared – A particular section of memory occupied by tmpfs (A type of file-system).
    • buff/cache – A combined section of memory occupied by kernel buffers and page cache. In order to display each value separately, we can run 'free -w' on the terminal.
    • available – An estimated amount of memory available for other applications to run. It includes free as well as certain reclaimable memory.
  • Swap – The information related to Swap Memory (alternate memory when RAM is full).
    • total – The total amount of Swap Memory supported by the system.
    • used – The amount of memory currently in use.
    • free – The section of memory that is free.

These values are obtained from meminfo file inside the proc file-system.

A key thing to note here is that the values for each field are presented in Kibibyte (KiB). A Kibibyte is 1024 byte, an alternative to Kilobyte (KB) which is 1000 bytes.


2. Human-Readable Output of the free Command

These large values are somewhat vague to the user, therefore free command supports a human-readable format. The term is an exaggeration of rounding off values to their nearest three figures with thoughtful use of byte units.

To avail this feature, we need to add '-h' option to the free command.

free -h
Free Command Human Readable
Human-Readable format

The values might seem different, but converting the respective byte measurements will lead to similar values. Moreover, RAM is being constantly used by the system, therefore every second the values differ by tiny amounts.

In the image, 'G' refers to Gigabyte, 'M' refers to Megabyte and so on.


3. Customize Byte Measurements

As we previously mentioned, there exist two variations of byte measurements. Let us look at how we can customize these units.

Kibibyte (KiB)

This set of byte measurements consider 1 kibibyte = 1024 bytes. Using this as a foundation, other measurements like Mebibyte (MiB) = 1024 KiB. We can apply this byte unit to the output of the free command by adding an option with the first letter of measurement word, like '-m' for Mebibyte, '-g' for Gibibyte, etc.

free -m
Free Command Mebibyte
free command output in Mebibyte

For more information, we can always refer to the manual pages of the command by running 'man free' on the Linux terminal.


Kilobyte (KB)

The standard byte measurements used in day-to-day lives. This kind of measurement considers a Kilobyte containing 1000 bytes. This leads to easy and fast calculations for converting to other byte units. To implement these byte units to the output of free command we need to add options like '--kilo' for kilobyte, '--mega' for megabyte and so on.

free --mega
Free Command Megabyte
free command output in Megabyte

We can check the correctness of these options by asking helping by the command itself by running 'free --help' or by simply running an incorrect option on the terminal.


Auto-update Output

Since the free command provides discrete values at a time instance, the command has few ways to monitor memory information continuously.

Duration-specific outputs

The output of the free command can be displayed with certain gap of seconds by:

free -s 3
Free Command Duration
Duration-specific output

The above command displays memory information after three seconds indefinitely.


Count-specific outputs

If we wish to display the output for a specific number of times, then '-c' option is used.

free -c 4
Free Command Number
Count-specific outputs

The time gap is set to one second by default. We can use a combination of duration and count to print continuous outputs.


Conclusion

There is not much into the free command except memory statistics of the system. We hope this guide to free command was understandable. Feel free to comment below for queries with respect to the topic.