Linux offers numerous commands to optimize the system’s performance. Among these, the “free” command is utilized to show the used and free memory of the working system. Moreover, the “free” command also analyzes the physical and swap memory. Considering the importance of the free command, this post offers the working and usage of the “free” command in Linux.
- What is the free Command in Linux?
- How to Use free Command in Linux?
What is the free Command in Linux?
The primary goal of the “free” command is to check the Linux system’s memory statistics. It is very useful for observing and monitoring the system’s memory usage.
The free command’s operations are dependent on the following syntax:
$ free [Options]
The syntax contains the main keyword “free”, whereas the square brackets tell about its supported “options”.
The essential supported options of the “free” command are described along with their description in the below table:
|-b||Shows the system memory in bytes.|
|-g||Display the total memory in gigabytes.|
|-m||Represents the system memory in megabytes.|
|-k||Shows the RAM usage statistics in kilobytes by default.|
|-t||Provides the total of free and used memory held by RAM and swap.|
|-s||Keep refreshing memory after N seconds.|
|-c||Exit the memory information after N times.|
|-l||Identifies the low and high memory statistics.|
For more details on options, use the help option of the command:
$ free --help
How to Use free Command in Linux?
This section describes all of these options with the help of practical examples.
Example 1: Display the Total Memory
Simply run the “free” command without any argument or option in the terminal (Ctrl+Alt+T). It provides the total RAM usage statistics:
The output of the “free” command displays the total memory RAM of the current system in the following format:
- Total: Displays the total used and swapped memory.
- Used: Shows the used memory by different processes.
- Free: Identifies the free system’s memory.
- Shared: Represent the memory shared with multiple processes.
- Buff/cache: Buffer is the memory that is reserved by the kernel while “cache” displays the recently accessed single or multiple file/system processes.
- Available: It is an estimated amount of memory that is present to start new applications without swapping.
Example 2: Shows the Total Memory in Specific Units
By default, the “free” command displays the memory usage statistics in kilobytes. The “free” command provides some specific options to get these statistics in other units. For example, the “-b” option displays the RAM usage in “bytes” units as shown below:
$ free -b
The “-m” option represents the “free” command output in “megabytes” units:
$ free -m
The “-g” option denotes the total system memory in “gigabytes” units:
$ free -g
Example 3: Shows the Total Memory Continuously
The “free” commands facilitate the Linux users to its unique options “-s” and “-c”. The “-s” option continuously shows the memory statistics on the terminal. However, the “-c” option refreshes the “free” command output each time and displays it on the screen after the specified interval set by the user.
The combination of “-s” and “-c” options refreshes the system memory information and displays it in the terminal after the particular time interval:
$ free -s 3 -c 2
Here, the output shows the current system memory usage two times after three seconds.
Example 4: Display the Total Sum of the System Memory
Typically, the “free” command provides the total, used, and free memory occupied by the RAM. But when we implement the command with the “-t” option, then it provides the total sum of physical and swap memory for the columns the total, free, and used in the output:
$ free -t
Here in the above output the third row “Total” specified the total sum of free, used, and total memory usage.
Example 5: Show the Total Memory in Human Readable Format
The “-h” stands for human-readable format. It represents the physical and swap memory in human-readable format, whether in gigabytes, megabytes, terabytes, etc. Type the below command on the terminal for checking the memory usage in human-readable format:
$ free -h
This is the best option to represent the system memory utilization statistics.
Example 6: Show the Total Memory Statistics
The “free” command with the combination of the “-l” option gives the detailed view of system memory, including high and low memory statistics:
$ free -l
The output shows the low and high memory of the current system.
In Linux, the “free” command is used to get the complete information of the “physical” and “swap” memory of the system. The generalized syntax of the “free” command is “$ free [Options]”. In addition, it supports a list of options that are very useful for getting the desired output. This guide fully describes the objective, usage, and working of the “free” comm