The free command in Linux: view RAM and swap usage

Introduction

In Unix-like operating systems, especially Linux, controlling hardware resources is fundamental to guarantee the performance and stability of applications. One of the most critical resources is memory, since both RAM and swap space directly influence the system’s ability to handle simultaneous processes. The free command has become a standard and quick tool to obtain a snapshot of memory usage in real time. In this article we will explore its operation, the most useful options, and how to interpret its data to make informed decisions in server and workstation administration.

What is the free command

Free is a program included in the procps-ng package that shows the amount of free and used memory, as well as swap space, in user-readable units. Unlike other utilities that require special permissions or complex configurations, free runs directly from the terminal and presents the information in a simple tabular format. Its origin dates back to the early Linux kernels, where the need to monitor memory led to creating a lightweight utility that could be used by both administrators and developers to debug performance problems.

Syntax and main options

The basic syntax of the command is: free [options]. Without options, free displays memory in kilobytes. The most common options include:

  • -b, –bytes: shows values in bytes.
  • -k, –kilobytes: shows in kilobytes (default value).
  • -m, –megabytes: shows in megabytes.
  • -g, –gigabytes: shows in gigabytes.
  • -h, –human: presents data with automatically readable units (e.g. 1.2G, 45M).
  • -s : updates the output every specified number of seconds.
  • -c : repeats the display a specified number of times before exiting.
  • -t, –total: adds a row showing the total of RAM plus swap.
  • -lo, –low: omits the buffers/cache column for a simpler view.

These options allow adapting the output to the needs of the moment, whether for a quick review or continuous monitoring.

Interpretation of the output

The typical output of free (without options) is presented as follows:

              total        used        free      shared  buff/cache   available
Mem:       8056744    3421128    2745600      123456     1889016    3890000
Swap:      2097148           0    2097148

Each column has a specific meaning:

  • total: total amount of memory available (RAM or swap).
  • used: memory currently in use by processes and the kernel.
  • free: memory completely unused.
  • shared: memory used by temporary file systems (tmpfs) and other sharings.
  • buff/cache: memory used by the kernel for input/output buffers and file cache; this memory can be freed quickly if needed.
  • available: estimate of how much memory is really available to launch new applications without resorting to swap, taking into account that part of buff/cache can be reused.

In the Swap row it indicates how much of the swap space is occupied; high swap usage can signal memory pressure and possible performance degradation.

Practical examples

Some everyday usage examples:

  1. View memory in human-readable format:

    free -h

    Output:

                  total        used        free      shared  buff/cache   available
    Mem:           7,8G        3,3G        2,6G        120M        1,8G        3,7G
    Swap:          2,0G          0B        2,0G
    
  2. Monitor every 5 seconds for 30 seconds:

    free -s 5 -c 6

  3. Show only the

    This post is also available in ESPAÑOL.

Leave a Reply

Your email address will not be published. Required fields are marked *

Esta obra está bajo una Licencia Creative Commons Atribución 4.0 Internacional para Francesc Roig francesc@vivaldi.net .