Updated April 18, 2023
Introduction to Linux Free Command
In the Linux operating system, the free command is used to get the information about the total amount of random access memory available with the amount of memory used and swap memory available in the system. The free command or utility also displays the buffer memory used by the kernel.
The free command-line utility was written by Brian Edmonds.
Syntax of Free command
free [options]
- free: Using the free keyword in the command | syntax. It will take the argument as an option and provide the result with memory information.
- option: We can provide different flags as options that are compatible with free command.
How Does Linux Free Command Work?
Free command is a very lightweight utility in Linux operating system. As per the free command option, it is displaying the memory information to the end-user. The output memory information will be indifferent variants like bytes, kb, MB, GB, etc.
There are seven major components available in the free command. However, the display information format will change but the component present as it is.
- total: The total amount of physical (RAM) memory is present in the system.
- used: It will display the used (RAM) memory
- free: it will display the unused (RAM) memory
- shared: it will display the total amount of memory used by the temporary file system.
- buffers: it will display the memory used by the kernel buffers
- cache: it will display the memory used by the page cache
- available: it will be the total amount of memory available to start the new application.
Examples of Linux Free Command
Here are the following examples mention below:
Example #1 – Free Command
The Linux free command is providing the information about memory and swap in kilobyte. It is the simplest way to get information about memory.
Command :
free
Explanation :
As per the above command, we can get the physical memory (RAM) as well as the swap memory information of Linux Machine. With the help of the “free” command, we are getting the memory information in kb format. In memory information, it is including the total memory, user memory, free memory, shared, buffer/cache memory, and available memory.
Output :
Example #2 – Free Command – with the “-b” option
The free command is providing the physical random access memory and swap memory information in byte format.
To get the memory information in a byte format. We need to use the “-b” option in the free command.
Command :
free -b
Explanation :
The Linux free command is a very lightweight command-line utility to get the memory information in a different format. With the help of the above free command, we are getting the physical random access memory and swap memory information in byte format. To get the same information we need to use the “-b” option in the free command.
Output :
Example #3 – Free Command – with “-m” option
The free command is providing the physical RAM and swap memory information in megabyte format.
To get the memory information in a megabyte format. We need to use the “-m” option in the free command.
Command :
free -m
Explanation :
In the Linux ecosystem, generally, the megabyte information is used to check the memory status. As per the above free command, we are getting the physical random access memory and swap memory information in megabyte format. To get the same information we need to use the “-m” option in the free command.
Output :
Example #4 – Free Command – with “-g” option
The free command is providing the physical RAM and swap memory information in gigabyte format.
To get the memory information in a gigabyte format. We need to use the “-g” option in the free command.
Command :
free -g
Explanation :
As per the Linux machine or Linux virtual machine, the gigabyte (“-g”) option will not work because the memory allocation is not more than a gigabyte. As per the above free command, we are getting the physical random access memory and swap memory information in gigabyte format. To get the same information we need to use the “-g” option in the free command.
Output :
Example #5 – Free command – with the “-h” option
In the Linux Free command, there is the facility to get the information of memory and swap information in a human-readable format.
To get the memory information in a human-readable format. We need to use the “-h” option in the free command.
Command :
free -h
Explanation :
If any person does not belong to IT or computer background then it would be more different to understand the memory information in megabyte or gigabyte format. To overcome this condition, we can use the above command to get the memory information in a human-readable format. To get the same information we need to use the “-h” option in the free command.
Output :
Example #6 -Free command – with the “-t” option
In free command, we can add one more extra row in the output to give more specific information about total memory statistics.
To get the memory information in an extra row format. We need to use the “-t” option in the free command.
Command :
free -t
Explanation :
As per the above free command, we are getting the memory information with the additional row. When we need total memory statistics i.e. addition of physical random access memory and swap memory with used status. Then we can use the “-t” option with the free command.
Output :
Example #7 – Free command – with “-s -c” option
In free command, we can get the memory information status after a specific interval of time.
We need to use the “-s” option for the time interval in the second and “-c” option to display the number of free commands.
Command :
free -s 2 -c 5
Explanation :
As per the above free command, we are getting the free command output every 2 sec and display the command output 5 times.
Output :
Conclusion
We have seen the uncut concept of “Linux Free Command” with the proper example, explanation, and command with different outputs. The free command is used to get the live physical random access memory and swap memory information of the Linux Machine. It will mainly use in system monitoring and alerting part of Linux Servers.
Recommended Articles
We hope that this EDUCBA information on “Linux Free Command” was beneficial to you. You can view EDUCBA’s recommended articles for more information.