Free Command in Linux

By 

•

Updated on

•

5 min read

Linux free Command

How much free RAM memory do I have available on my Linux system? Is there enough free memory to install and run new applications?

In Linux systems, you can use the free command to get a detailed report on the system’s memory usage. This guide explains how to use the free command in Linux and interpret the output.

The free command provides information about the total amount of the physical and swap memory, as well as the free and used memory.

How to Use the free Command

The syntax for the free command is as follows:

Terminal
free [OPTIONS]

When used without any option, the free command will display information about the memory and swap in kibibytes. 1 kibibyte (KiB) is 1024 bytes.

Terminal
free

The output will include three lines, a header, one line for the memory and one for the swap:

output
              total        used        free      shared  buff/cache   available
Mem:        8075208     4093048     1310540      551232     3559704     3982160
Swap:       2097148           0     2097148
Info
Older versions of free calculate the used column differently, so the numbers on a long-lived server may not line up with the explanation below.

Here is what each column means:

  • total - This number represents the total amount of memory that can be used by the applications.
  • used - Used memory, calculated as total - available. Versions of free older than procps-ng 3.3.12 used total - free - buffers - cache instead, which is why the same machine can report a lower used value under an older release.
  • free - Free / Unused memory.
  • shared - Memory used by tmpfs and shared memory segments. On older kernels this column may show zero.
  • buff/cache - The combined memory used by the kernel buffers and page cache and slabs. This memory can be reclaimed at any time if needed by the applications. If you want buffers and cache to be displayed in two separate columns, use the -w option.
  • available - An estimate of the amount of memory that is available for starting new applications, without swapping.

Showing Memory Usage in Human Readable Format

By default, the free command shows the memory information in kibibytes. To view the information in human-readable format, scaled to mebibytes and gibibytes, use the -h option:

Terminal
free -h
output
              total        used        free      shared  buff/cache   available
Mem:           7.7Gi       3.9Gi       1.2Gi       538Mi       3.4Gi       3.8Gi
Swap:          2.0Gi          0B       2.0Gi

Showing Memory Usage in Other Metrics

The free command also allows you to specify the unit in which the memory is measured. Valid options are:

  • -b, --bytes - Display output in bytes.
  • --kilo - Display output in kilobytes (1KB = 1000bytes).
  • --mega - Display output in megabytes.
  • --giga - Display output in gigabytes.
  • --tera - Display output in terabytes.
  • -k, --kibi - Display output in kibibytes. (1KiB = 1024bytes). This is the default unit.
  • -m, --mebi - Display output in mebibytes.
  • -g, --gibi - Display output in gibibytes.
  • --tebi - Display output in tebibytes.
  • --peti - Display output in pebibytes.
  • --si - Instead of 1024, use powers of 1000. For example --mebi --si is equal to --mega.

For example, to show the output in megabytes, you would type:

Terminal
free --mega
output
              total        used        free      shared  buff/cache   available
Mem:           8269        4191        1341         564        3645        4077
Swap:          2147           0        2147

To show output in mebibytes:

Terminal
free -m
output
              total        used        free      shared  buff/cache   available
Mem:           7885        3997        1279         538        3476        3888
Swap:          2047           0        2047

Showing the Column Totals

To display a line showing the column totals, use the -t option. This gives you a sum of the memory and swap in the total, used and free columns.

Terminal
free -h -t
output
              total        used        free      shared  buff/cache   available
Mem:           7.7Gi       3.9Gi       1.2Gi       538Mi       3.4Gi       3.8Gi
Swap:          2.0Gi          0B       2.0Gi
Total:         9.7Gi       3.9Gi       3.2Gi

Continuously Print the Output

To continuously display the memory information on the screen, invoke free with the -s (--seconds) option followed by a number that specifies the delay.

For example, to print the memory information every five seconds you would run:

Terminal
free -s 5

The free command will continue to display the result until you press CTRL+C. This is similar to the behavior of the watch command .

To display the result for a specific number of times, use the -c (--count) option. In the example below the command will print the result ten times:

Terminal
free -s 5 -c 10

Quick Reference

TaskCommand
Show memory in human-readable formatfree -h
Show output in megabytesfree --mega
Show totals linefree -t
Refresh every 5 secondsfree -s 5
Show 10 updatesfree -s 5 -c 10

FAQ

What is the difference between “free” and “available”?
“Free” is memory not used at all. “Available” includes memory that can be reclaimed from caches and buffers, and is a better estimate of how much memory you can use without swapping.

Why is used memory so high even when I am not running much?
Since procps-ng 3.3.12 the used column is total - available, so page cache that can be reclaimed no longer inflates it. A high value points at memory that really is unavailable, such as tmpfs filesystems counted in the shared column or kernel slab allocations that cannot be freed. On an older release the same column also counts the cache, which is the usual reason for a surprising number.

Is free enough, or should I use top/htop?
free provides a quick snapshot of memory usage. Use top or htop if you need per-process details and live monitoring.

Conclusion

We have shown you how to use the free command to check the system’s memory usage and interpret the command output. If a process was killed after memory ran low, our guide on diagnosing OOM killer events shows how to confirm it. To view all available options type man free in your terminal.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page