Open In App

free Command in Linux with examples

Last Updated : 09 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report
News Follow

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 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:

  1. total displays the total installed memory (MemTotal and SwapTotal i.e present in /proc/meminfo).
  2. used displays the used memory.
  3. free displays the unused memory.
  4. shared displays the memory used by tmpfs(Shmen i.e. present in ‘/proc/meminfo’ and displays zero in case not available).
  5. buffers displays the memory used by kernel buffers.
  6. cached displays the memory used by the page cache and slabs(Cached and Slab available in ‘/proc/meminfo’).
  7. 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
free -b option

2. Using ‘-k’ (Displaying Output in Kilobytes)

This option displays the result in kilobytes. The following is the command of its usage:

free -k
free -k options

3. Using ‘-m’ (Displaying Output in Megabytes)

This option displays the result in megabytes. The following is the command of its usage:

free -m
free -m option

4. Using ‘-g’ (Displaying Output in Gigabytes)

This option displays the result in gigabytes. The following is the command of its usage:

free -g

displaying the ram usage in gigabytes

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
free-t option

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
Usage of -s and -c options with free command

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.



Next Article

Similar Reads

three90RightbarBannerImg