free – Show memory usage

The free command is used to display the amount of free and used memory in the system. It can also display the amount of swap space and its utilization. This command is useful in determining the memory usage of the system and can help in troubleshooting memory-related issues.

Overview

The free command displays the total amount of free and used physical and swap memory in the system, as well as the buffers and caches used by the kernel.

To use the free command, simply type free in the terminal. The output will show the following columns:

  • total – the total amount of physical memory in the system
  • used – the amount of physical memory currently in use
  • free – the amount of physical memory currently available for use
  • shared – the amount of shared memory
  • buffers – the amount of memory used by buffers
  • cached – the amount of memory used by caches

The output also includes information on swap memory:

  • swap total – the total amount of swap space in the system
  • swap used – the amount of swap space currently in use
  • swap free – the amount of swap space currently available for use

The free command can also be used with the -h option to display the output in a more human-readable format:

$ free -h

Use Cases

  • To check the memory usage of the system
  • To troubleshoot memory-related issues
  • To monitor memory usage over time

Options

The following table lists the available options for the free command:

Option Description
-b Display output in bytes
-k Display output in kilobytes (default)
-m Display output in megabytes
-g Display output in gigabytes
-h Display output in a human-readable format
-s N Display memory usage N times with a delay of 1 second between each display

Troubleshooting Tips

  • If the system is running low on memory, try closing unnecessary applications or services to free up memory.
  • If the system is frequently running out of memory, consider upgrading the system’s RAM or adding more swap space.

Notes

  • The free command is included in most Linux distributions and does not require any additional installation.
  • The output of the free command may vary depending on the version of the command and the Linux distribution being used.