free Command in Linux with examples
Last Updated :
09 Sep, 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 the amount of free memory available on your system. In LINUX, there exists a command line utility for this and that is the ‘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.
What is the ‘free’ Command?
The `free` command in Linux is the one that facilitates with providing the overview of system memory utilization. It displays all the details regarding the RAM usage such as how is the total, what is used, and free memory including buffers and cached data, aiding in real-time monitoring of memory resources. It acts as essential command for administrators and users to assess system performance, allocate resources effectively, and identify potential memory-related issues promptly.
Syntax:
The basic syntax of the “free” command is as follows:
free [OPTION]
Common Options of ‘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.
The following are the some of the optiosn of linux free command:
| Options |
Description |
| -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. |
Basic Usage of ‘free’ Command
The following command helps in finding the usage of ram memory in the system:
free
The following screenshot illustrates with displaying the usage of ram memory:
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.e. present 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.
Usage and Examples of free command with options
The following are options and examples discussing the usage of free command with options:
1. Using ‘-b’ (Displaying Output in Bytes)
It just displays the output in unit bytes. The following is the command of its usage:
free -b
2. Using ‘-k’ (Displaying Output in Kilobytes)
This option displays the result in kilobytes. The following is the command of its usage:
free -k
3. Using ‘-m’ (Displaying Output in Megabytes)
This option displays the result in megabytes. The following is the command of its usage:
free -m
4. Using ‘-g’ (Displaying Output in Gigabytes)
This option displays the result in gigabytes. The following is the command of its usage:
free -g

5. Using ‘-t’ (Displaying Totals with the -t Option)
This option displays an additional line containing the total of the total, used and free columns.
free -t
5. Using ‘-s’ and ‘-c’ (Continuously Monitoring Memory Usage)
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

f
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.
Importance of Linux ‘free’ Command
The following are the some of the important points of linux free commmand:
- Real-time Memory Monitoring: It faiclitates with provides the immediate insight regarding the system memory usage. It helps the administrators and users in monitoring the resource allocation.
- Performance Optimization: It llows the users for proactive management by identifying memory-intensive processes or applications, enabling timely adjustments to improve overall system performance.
- Resource Planning: It facilitates with efficient resource planning and allocation decisions based on accurate data about available, used, and cached memory, ensuring optimal utilization of system resources.
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.
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
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
Similar Reads
fc Command in Linux with Examples
As we all know that LINUX is command friendly and while working on LINUX, you may deal with very long commands that may include long paths or really difficult syntax, and imagine what if working with such commands you do a minor mistake which will require re-writing of the entire command synopsis an
3 min read
fc-cache command in Linux with Examples
The fc-cache command in Linux scans the font directories and build font cache for applications which use fontconfig for their font handling. When no arguments are passed fc-cache scans each directory for font files readable by FreeType. A cache is created which contains properties of each font and t
2 min read
fc-list command in Linux with examples
fc-list command is a part of the fontconfig system. It is used to list the available fonts and font styles. Using the format option, the list of all fonts can be filtered and sorted out. Moreover, multiple parameters can be passed to it after a colon symbol (:) to restrict the information that is be
3 min read
fdisk command in Linux with examples
The 'fdisk' command in Linux, short for "format disk," is a powerful, dialog-driven utility used for creating and manipulating the disk partition table. Essential for system administrators and users looking to manage their hard drive’s structure, 'fdisk' supports a range of operations such as creati
5 min read
fg command in Linux with examples
The fg command in Linux is used to bring a background job into the foreground. It allows you to resume a suspended job or a background process directly in the terminal window, so you can interact with it. Syntaxfg [job_spec]The job_spec is a way to refer to the background jobs that are currently run
3 min read
fgrep command in Linux with examples
The 'fgrep' filter is used to search for the fixed-character strings in a file. There can be multiple files also to be searched. This command is useful when you need to search for strings that contain lots of regular expression metacharacters, such as "^", "$", etc. This makes 'fgrep' particularly v
4 min read
file command in Linux with examples
The 'file' command in Linux is a vital utility for determining the type of a file. It identifies file types by examining their content rather than their file extensions, making it an indispensable tool for users who work with various file formats. The file type can be displayed in a human-readable f
3 min read
How to Find a File in Linux | Find Command
Linux, renowned for its robust command-line interface, provides a suite of powerful tools for efficient file and directory management. Among these, the "find" command stands out as an indispensable asset, offering unparalleled versatility in searching for files based on diverse criteria. This articl
9 min read
Finger command in Linux with Examples
The 'finger' command is a powerful utility in Linux used to display information about users logged into the system. This command is commonly used by system administrators to retrieve detailed user information, including login name, full name, idle time, login time, and sometimes the user's email add
4 min read
fmt command in Linux with examples
fmt command in LINUX actually works as a formatter for simplifying and optimizing text files. Formatting of text files can also be done manually, but it can be really time-consuming when it comes to large text files, this is where fmt comes to rescue. fmt re-formats each paragraph in the file specif
4 min read
fold command in Linux with examples
The fold command in Linux wraps each line in an input file to fit a specified width and prints it to the standard output. By default, it wraps lines at a maximum width of 80 columns, which is configurable. To fold input using the fold command pass a file or standard input to the command. Syntax of `
3 min read
for command in Linux with Examples
IntroductionThe for command in linux used in shell scripting to iterate over a set of values or perform set of tasks repeatedly. The for loop allows users to automate operations efficiently which is easier to maintain. Syntax: for NAME [in WORDS ... ] ; do COMMANDS; doneHere NAME takes the value of
2 min read
free Command in Linux with examples
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 the amount of free memory available on your system. In LINUX, there exists a command line utility for this and that is the 'free' command which displays the total amoun
6 min read
Fun Commands in Linux
Linux isn't just for coding and administration—it can also be a lot of fun. With a variety of terminal commands, you can add some entertainment to your Linux experience. Below is a list of some cool and fun commands you can use in Linux to enhance your terminal experience. We’ll also cover how to in
4 min read
function command in Linux with examples
The function is a command in Linux that is used to create functions or methods. It is used to perform a specific task or a set of instructions. It allows users to create shortcuts for lengthy tasks making the command-line experience more efficient and convenient. The function can be created in the u
2 min read
Compiling with g++
g++ command is a GNU c++ compiler invocation command, which is used for preprocessing, compilation, assembly and linking of source code to generate an executable file. The different "options" of g++ command allow us to stop this process at the intermediate stage. Check g++ compiler version informa
3 min read
gawk command in Linux with Examples
The gawk command in Linux is a pattern scanning and processing language. No compilation is required, and variables can be used along with numeric functions, string functions, and logical operators. Gawk is a utility that enables programmers to write highly compact but still effective programs as sta
3 min read
gcc command in Linux with examples
GCC stands for GNU Compiler Collections which is used to compile mainly C and C++ language. It can also be used to compile Objective C and Objective C++. The most important option required while compiling a source code file is the name of the source program, rest every argument is optional like a wa
2 min read
gdb command in Linux with examples
GDB, the acronym for GNU Debugger, is a powerful debugging tool used to analyze and debug programs written in languages like C, C++, Ada, and Fortran. It allows developers to inspect the behavior of their programs, step through code, set breakpoints, and examine variable values in real-time. GDB is
8 min read
getent command in Linux with examples
The 'getent' command in Linux is a powerful tool that allows users to access entries from various important text files or databases managed by the Name Service Switch (NSS) library. This command is widely used for retrieving user and group information, among other data, stored in databases such as '
5 min read
gpasswd Command in Linux with examples
gpasswd command is used to administer the /etc/group and /etc/gshadow. As every group in Linux has administrators, members, and a password. It is an inherent security problem as more than one person is permitted to know the password. However, groups can perform co-operation between different users.
4 min read
grep command in Unix/Linux
The grep command in Unix/Linux is a powerful tool used for searching and manipulating text patterns within files. Its name is derived from the ed (editor) command g/re/p (globally search for a regular expression and print matching lines), which reflects its core functionality. grep is widely used by
7 min read
How to Create a new group in Linux | groupadd command
In the Linux operating system, user management is a crucial aspect of system administration. One of the fundamental tasks is creating and managing user groups. Groups in Linux allow administrators to organize and control user access to various resources and files. The groupadd command is a powerful
7 min read
How to Delete a Group in Linux | groupdel command
Group management is a crucial aspect of Linux system administration, and understanding how to create, modify, and delete groups is essential for maintaining a secure and organized environment. In this article, we will delve into the process of deleting a group in Linux using the 'groupdel' command.
3 min read
groupmod command in Linux with examples
groupmod command in Linux is used to modify or change the existing group on Linux system. It can be handled by superuser or root user. Basically, it modifies a group definition on the system by modifying the right entry in the database of the group. Syntax: groupmod [option] GROUP Files: The groupmo
2 min read