Linux free Command Tutorial with Examples

The Linux free command is used to display current memory usage. The free command can be used to show how much RAM memory is available. Is there enough memory to run a new application? etc. The free command is a very simple command which simply shows few lines about the memory. The free command can be used to show total memory, used memory, free memory, shared memory, and available memory about RAM and swap space.

free Command Syntax

The free command is very simple and the syntax of the free command is very simple like below. The OPTION is optional.

free OPTION
  • OPTION is used to set different display types. The OPTION is optional.

Show Memory/RAM Usage with free Command

The free command can be executed without any option. This shows the memory and swap usage about the system. The memory usage displayed as byte which means the memory unit is byte. There are different columns about different memory usage like total memory, used memory, free memory, shared memory, buffer/cache memory, available memory.

Show Memory/RAM Usage with free Command
          total        used        free      shared    buff/cache   available
 Mem:        3997300          1534956     1157240                7452     1305104           2168376
 Swap:       2097148           0                 2097148
  • total column shows total memory installed on the current system. In this example total memory is 3997300 byte wich is about 4GB.
  • used memory is currently used memory size. In this example used memory size is about 1534956 bytes wich is about 1.5 GB.
  • free memory column shows completely free and unused memory size. In this example free memory size is 1157240 bytes which is about 1 GB.
  • shared memory column shows the shared memory size which is used by multiple processes and applications.
  • buff/cache memory column shows the cached or buffered memory size which is current not actively used but stored later usage.
  • avaiable memory column displays the currently useable memory size where free memory and buffer/cache can be used.

Show Memory Usage In Human Readable Format

By default, the free command displays memory sizes as a byte unit. For modern systems, the byte display is not practical and easy to read. To make things more easier and human-readable the different memory sizes can be displayed in GigaByte or MegaByte or KiloByte. The -h option is used to display memory size human-readable and pretty format which translates bytes to the gigabytes.

free -h
          total    used        free      shared  buff/cache   available
 Mem:          3,8Gi       1,5Gi              1,1Gi             7,0Mi              1,2Gi              2,1Gi
 Swap:         2,0Gi          0B                2,0Gi

Show Memory Usage In Human Readable Format As GigaByte (GB)

The memory sizes or memory size unit can be shown as Gigabyte or GB by using the –giga option like below.

free --giga

Show Memory Usage In Human Readable Format As KiloByte (KB)

The memory sizes or memory size unit can be shown as Gigabyte or GB by using the –kilo option like below.

free --kilo

Show Memory Usage In Human Readable Format As MegaByte (MB)

The memory sizes or memory size unit can be shown as Gigabyte or GB by using the –mega option like below.

free --mega

Continuously Show Memory Usage

The memory usage should be monitored and tracked continuously. The free command can print the memory usage continuously for specified intervals. the -s option can be used to set continuous display intervals like 3 seconds 5 seconds etc. In the following example, the free command displays the memory usage every 10 seconds automatically.

free -s 10

Leave a Comment