free Command in Linux



The free command in Linux displays the amount of free and used memory in the system. It displays the total amount of free and used physical and swap memory along with the buffer used by the kernel.

The free command assists in providing an overview of memory utilization by the system. It displays the system and swap memory in total, free, used, shared, buff/cache, and available columns.

Table of Contents

Here is a comprehensive guide to the options available with the free command −

Syntax of free Command

The syntax of Linux free command is as follows −

free [options]

The [options] field is used to specify options to display the output in different formats.

Options of free Command

The options of the free command are listed below −

Flags Options Description
-b --byte It displays memory in bytes
-k --kibi It displays memory in kibibytes (KiB)
-m --mebi It displays memory in mebibytes (MiB)
-g --gibi It displays memory in gibibytes (GiB)
--tebi It displays memory in tebibytes (TiB)
--pebi It displays memory in pebibytes (PiB)
--kilo It displays memory in kilobytes (kB)
--mega It displays memory in megabytes (MB)
--giga It displays memory in gigabytes (GB)
--tera It displays memory in terabytes (TB)
--peta It displays memory in petabytes (PB)
-h --human It displays output in a human-readable format
-w --wide It switches to the wide mode (displays buffer and cache in separate columns)
-c count --count count It displays the output in count times
-l --lohi It shows the details in low and high memory statistics
-L --line It shows output in a single line
-s delay --second delay It keeps on displaying output after the specified delay
--si It uses SI units (kilobytes, megabytes, gigabytes) instead of binary units (kibibytes, mebibytes, gibibytes)
-t --total It displays an additional row showing a total of columns
-v --committed It displays a line showing the memory commit limit
--help It displays help related to the free command
-V --version It displays the command version

Examples of free Command in Linux

This section demonstrates the usage of the free command in Linux with examples −

Displaying Memory

To display the memory usage in Linux, use the free command without any option −

free

It displays the output in bytes −

free Command in Linux1

The output has six columns and two rows.

Mem It displays memory information of physical RAM
Swap It displays the memory information of the swap (swap memory is memory on the hard drive used as virtual memory)

The column details are given in the table below −

total It shows the total amount of memory
used It shows the amount of memory currently in use
free It shows the unused amount of memory
shared It shows the memory shared by multiple processes
buff/cache It shows the memory used by the kernel for buffer and cache
available It shows available memory for new processes without a swap

Displaying Memory in Various Formats

To display the usage of RAM and swap memory in mebibytes, use the -m option −

free -m

One mebibyte is equal to 1,048,576 bytes. Similarly, to display the output in gibibytes, use the -g option −

free -g
free Command in Linux2

Displaying Memory in Megabytes

To display memory usage in the megabytes, use the --mega option −

free --mega
free Command in Linux3

Displaying Memory in Gigabytes

To display RAM usage in gigabytes, use the --giga option −

free --giga
free Command in Linux4

Displaying Memory in Human Readable Format

By default, the free command displays output in bytes. To display the free memory in a human-readable format, use the -h or --human format −

free -h
free Command in Linux5

Displaying Memory in Wide Format

The wide format produces lines longer than 80 characters. It also displays the buffer and cache separately.

free -w
free Command in Linux6

Displaying Memory Multiple Times

To display the free memory output multiple times at specified intervals, use the -s/--second and -c/--count options −

free -s 3 -c 2
free Command in Linux7

The command displays the output twice, with a second output after three seconds.

Displaying Memory with Low & High Statistics

To display the output with low and high memory statistics, use the -l or --lohi option −

free -l
free Command in Linux8

Displaying Memory in One Line

To display the output in one line, use the -L or --line option −

free -L
free Command in Linux9

Displaying Memory with Commit Limit

The committed memory is a memory allocated for a system or applications. To display an additional row of committed memory, use the -v or --committed option −

free -v
free Command in Linux10

Displaying Memory with Total

To display a row of Total, use the -t or --total options −

free -t
free Command in Linux11

The above command adds a row of the total.

Conclusion

The free command in Linux displays the RAM and swap usage in the standard output. It is a powerful utility that shows memory usage in various formats. Moreover, it is used for managing resources and system performance improvement of the system.

In this tutorial, we explained the free command, its syntax, options, and usage in Linux with examples.

Advertisements