free Command in Linux with examples
Last Updated :
29 Apr, 2024
While using LINUX there might come a situation when you are willing to install a new application (big in size) and you wish to know for the amount of free memory available on your system. In LINUX, there exists a command line utility for this and that is free command which displays the total amount of free space available along with the amount of memory used and swap memory in the system, and also the buffers used by the kernel. This is pretty much what free command does for you.
Basic Syntax of free Command
The basic syntax of the “free” command is as follows:
free [OPTION]
OPTION : refers to the options compatible with free command.
As free displays the details of the memory related to your system , its syntax doesn’t need any arguments to be passed but only options which you can use according to your wish.
Basic Usage free Command
You can use the free command as:
free
free command in Linux
Free command without any option shows the used and free space of swap and physical memory in KB
When no option is used then free command produces the columnar output as shown above where column:
- total displays the total installed memory (MemTotal and SwapTotal i.e present in /proc/meminfo).
- used displays the used memory.
- free displays the unused memory.
- shared displays the memory used by tmpfs(Shmen i.epresent in /proc/meminfo and displays zero in case not available).
- buffers displays the memory used by kernel buffers.
- cached displays the memory used by the page cache and slabs(Cached and Slab available in /proc/meminfo).
- buffers/cache displays the sum of buffers and cache.
Options for free command
Option |
Description |
-b, –bytes |
Displays memory usage in bytes. |
-k, –kilo |
Displays memory usage in kilobytes (default). |
-m, –mega |
Displays memory usage in megabytes. |
-g, –giga |
Displays memory usage in gigabytes. |
–tera |
Displays memory usage in terabytes. |
-h, –human |
Automatically scales all output columns to the shortest three-digit unit and displays the units (B, K, M, G, T). |
-c, –count |
Displays the output ‘c’ number of times; works with the -s option. |
-l, –lohi |
Shows detailed low and high memory statistics. |
-o, –old |
Disables the display of the buffer-adjusted line. |
-s, –seconds |
Continuously displays the output after ‘s’ seconds delay. Uses the usleep system call for microsecond resolution delay times. |
-t, –total |
Adds an additional line in the output showing column totals. |
–help |
Displays a help message and exits. |
-V, –version |
Displays version information and exits. |
Using free command with options
Using -b :
It just displays the output in unit bytes.
free -b
free -b option
Everything now is displayed in bytes.
Using -k :
This option displays the result in kilobytes.
free -k
free -k option
Using -m :
This option displays the result in megabytes.
free -m
free -m option
We use this option to display it in megabytes.
Using -g :
This option displays the result in gigabytes.
free -g
We use this option to display it in gigabytes.
Using -t (total) :
This option displays an additional line containing the total of the total, used and free columns.
free -t
free-t option
The line containing total is added to the output when -t is used
Using -s and -c:
This option allows you to display the output of free command after a set time gap given by the user. This option requires a numeric value to be passed with it that is treated as the number of seconds after which the output will be displayed.
free -s 3 -c 3
free -s 3 -c 3
The above output will be displayed (only 3 times) after every 3 seconds. Now, with -s you can only specify the time gap but not the number of times you want the output to be displayed. For this, -c is used along with -s specifying the number of times the output will be displayed.
Free Command in Linux – FAQs
What is the free
command used for?
The free
command is used to display information about the amount of free and used memory in the system, including both physical memory (RAM) and swap space.
What are the different columns displayed by the free
command?
The free
command typically displays the following columns: total
(total installed memory), used
(used memory), free
(unused memory), shared
(memory shared between processes), buff/cache
(memory used for buffers and cache), and available
(estimation of memory available for new processes without swapping).
How can I display the output in bytes instead of the default kilobytes?
To display the output in bytes instead of kilobytes, you can use the -b
or --bytes
option with the free
command.
For example:
free -b
What is the difference between the free
and vmstat
commands?
While both free
and vmstat
commands provide information about memory usage, free
provides a snapshot of the current memory usage, whereas vmstat
provides more detailed memory statistics over time and includes additional information about CPU, I/O, and other system resources.
How can I continuously monitor memory usage with the free
command?
To continuously monitor memory usage with the free
command, you can use the watch
command in combination with free
.
For example: To update the memory usage information every second.
watch -n 1 free
Conclusion
The free
command is used in Linux to check the amount of free and used memory on your system. It shows details about the RAM (physical memory) and swap space usage. The output displays different columns like total memory, used memory, free memory, and memory used for caching. You can use various options with free
to change the units (bytes, kilobytes, etc.), show a continuous update of memory usage, or display totals. The free
command is very useful for monitoring how much memory is available on your Linux system before running big programs or installing new applications.
Share your thoughts in the comments
Please Login to comment...