Introduction
The Linux free command is a powerful tool for monitoring the memory usage of your system. It provides a quick and easy way to view the amount of free and used memory in your system, as well as the amount of memory that is being used by the kernel and other processes. This information can be used to identify potential memory issues and help you make decisions about how to optimize your system’s memory usage. In this guide, we will discuss the basics of the free command and how to use it to monitor your system’s memory usage.
Using the Linux free Command
The free command is a Linux command line utility used to display the amount of free and used memory in the system. It can also be used to display the amount of swap space available. The free command displays the total amount of free and used physical and swap memory in the system, as well as the buffers used by the kernel. It can also display the total amount of memory used by the system, the amount of memory used by the kernel, and the amount of memory used by user processes.
Introduction
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.
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.
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.
Using the Linux free Command
The Linux free command is a tool used to display the amount of free and used memory in the system. It can be used to monitor memory usage and to determine if the system is running low on memory. This article will explain how to use the free command and what the output means.
Using the Free Command
The free command is a simple command that can be used to display the amount of free and used memory in the system. To use the command, simply type “free” at the command prompt. The output will look something like this:
total used free shared buff/cache available Mem: 8174520 5144520 144500 84500 2585504 2514500 Swap: 8388604 0 8388604
The output is divided into three sections: total, used, and free. The total section shows the total amount of memory in the system. The used section shows the amount of memory that is currently being used. The free section shows the amount of memory that is not being used. The shared section shows the amount of memory that is shared between multiple processes. The buff/cache section shows the amount of memory that is used for caching and buffering. The available section shows the amount of memory that is available for use.
Interpreting the Output
The output of the free command can be used to determine the amount of free and used memory in the system. If the used memory is close to the total memory, then the system is running low on memory and may need to be upgraded. If the free memory is close to the total memory, then the system has plenty of memory and is not running low.
The output of the free command can also be used to determine if the system is running out of swap space. Swap space is used when the system runs out of physical memory and needs to use virtual memory. If the swap space is close to zero, then the system is running out of swap space and may need to be upgraded.
Conclusion
The Linux free command is a useful tool for monitoring memory usage and determining if the system is running low on memory or swap space. By understanding the output of the free command, you can determine if the system needs to be upgraded or if it has enough memory and swap space.