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.
- A system running Linux
- Access to a terminal (Ctrl+Alt+T)
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
free command takes the following syntax:
[options] are discussed in the following section, and they are optional.
free command without options outputs information about memory and swap, expressed in kibibytes:
Each column depicts the following:
|Total RAM amount available on the system.
|Memory currently in use by processes.
|Unused memory, free.
|Memory shared by multiple processes.
|Memory in use by the kernel (for buffers, page cache, and slabs).
|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:
|Displays the memory amounts in bytes.
|Displays the memory amounts in kibibytes. The command uses kibibytes by default.
|Displays the memory amounts in mebibytes.
|Displays the memory amounts in gibibytes.
|Displays the memory amounts in tebibytes.
|Displays the memory amounts in pebibytes.
|Scales and formats the output to the shortest three-digit unit to produce a human-readable output.
|Updates the output
|Show detailed low and high memory statistics.
|Continuously updates the output every
|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
|Displays a line showing the column totals.
|Prints the help file.
|Displays the program version.
free Command Examples
The following section shows different ways of using the
Example 1: Output Memory Usage in Human Readable Format
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
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
-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:
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:
The command produces an output with values expressed in mebibytes.
2. For powers of 1000, use:
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
-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
cache columns separately, specify the
The output now shows a
buffers column and a
cache column separately.
Example 6: Show the Total Memory Column
--total option instructs
free to print a
Total line that sums the values from the
free columns of the
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
free command options to automate and facilitate memory monitoring in a system. For example, combine the
-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.
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.