The Linux free command outputs a summary of RAM usage, including total, used, free, shared, and available memory and swap space. The command helps monitor resource usage and allows an admin to determine if there's enough room for running new programs.
In this tutorial, you will learn to use the free command in Linux.

Prerequisites
- A system running Linux
- Access to a terminal (Ctrl+Alt+T)
Note: The free command is a great way to monitor RAM usage on a server. However, the best way to secure a smooth server operation is to secure sufficient resources for running all apps. Choose one of our pre-configured Bare Metal Cloud server instances that best suits your needs and never run out of resources.
free Command Syntax
The free command takes the following syntax:
free [options]
[options] are discussed in the following section, and they are optional.
Running the free command without options outputs information about memory and swap, expressed in kibibytes:

Each column depicts the following:
| Column | Description |
|---|---|
total | Total RAM amount available on the system. |
used | Memory currently in use by processes. |
free | Unused memory, free. |
shared | Memory shared by multiple processes. |
buff/cache | Memory in use by the kernel (for buffers, page cache, and slabs). |
available | Estimated memory amount available for starting new applications, excluding swap. |
free gathers information by parsing the /proc/meminfo file.
Note: Learn about other Linux commands for checking memory usage.
free Command Options
Use options to customize and format the output. The free command accepts the following options:
| Option | Description |
|---|---|
-b, --bytes | Displays the memory amounts in bytes. |
-k, --kibi | Displays the memory amounts in kibibytes. The command uses kibibytes by default. |
-m, --mebi | Displays the memory amounts in mebibytes. |
-g, --gibi | Displays the memory amounts in gibibytes. |
--tebi | Displays the memory amounts in tebibytes. |
--pebi | Displays the memory amounts in pebibytes. |
-h, --human | Scales and formats the output to the shortest three-digit unit to produce a human-readable output. |
-c, --count [count] | Updates the output [count] times. |
-l, --lohi | Show detailed low and high memory statistics. |
-s, --seconds [delay] | Continuously updates the output every [delay] seconds. |
--si | Use power of 1000 (KB, MB, GB, etc.) instead of power of 1024 (KiB, MiB, GiB, etc.). For example, use --mebi --si to format the output in megabytes. Alternatively, use --kilo, --mega, --giga, and --tera. |
-t, --total | Displays a line showing the column totals. |
--help | Prints the help file. |
-V, --version | Displays the program version. |
free Command Examples
The following section shows different ways of using the free command.
Example 1: Output Memory Usage in Human Readable Format
The free command displays memory sizes in bytes by default, which isn't practical in modern systems with large amounts of RAM. Make the free command output easier to read by specifying the -h option:
free -h

The command formats the output using the most appropriate unit for each value - KiB, MiB, GiB, etc.
Note: Limit the amount of system resources a user can consume with the ulimit command.
Example 2: Continuously Show Memory Usage
Use the -s option to continually refresh the free command output and monitor an app's resource usage. Invoke the free command with the -s option and specify the delay between each output refresh:
free -s2

The example above instructs free to refresh the output every two seconds. Stop the process with Ctrl+C.
Example 3: Specify Output Units
Specify a unit for displaying the memory values uniformly. Use powers of 1024 (the default) or 1000.
1. For powers of 1024, use:
-b,--bytes-k,--kibi-m,--mebi-g,--gibi--tebi--pebi
For example:
free -m

The command produces an output with values expressed in mebibytes.
2. For powers of 1000, use:
--kilo--mega--giga--tera--peta
For example:
free --mega

The output values are expressed in megabytes. Alternatively, use the --si option followed by the corresponding power of 1024 unit:
free --si --m

The output values are expressed in megabytes.
Example 4: Print Output Multiple Times
Specify the -c option to instruct free to automatically quit after refreshing the output a specific number of times. In the following example, the command prints the result four times:
free -c 4

After four updates, the command automatically quits.
Note: Run any command in regular intervals with the Linux watch command.
Example 5: Separate Buff and Cache Columns
The buff and cache areas interact and depend on each other, so they are combined in the output. To see the buffers and cache columns separately, specify the -w option:
free -w

The output now shows a buffers column and a cache column separately.
Example 6: Show the Total Memory Column
The --total option instructs free to print a Total line that sums the values from the total, used, and free columns of the Mem and Swap lines.
free -h --total

In the example above we instructed free to show the Total line and produce the output in a human-readable format.
Example 7: Combine Options
Combine different free command options to automate and facilitate memory monitoring in a system. For example, combine the -s and -c options to make free produce an output several times with a delay between refreshes:
free -m -s3 -c4

The command runs four times with a three-second delay between updates and expresses the values in mebibytes.
Conclusion
This tutorial showed how to use the free command to monitor memory usage on a Linux system. The command allows system administrators to monitor RAM usage on a system or server. Therefore, it is a helpful utility for identifying a potential issue. Learn more about system memory by reading our article on the differences between Intel Optane, RAM, and SSD.


