The free command in Linux: see the use of RAM and swap

Introduction

In Unix operating systems, especially in Linux, hardware resource control is essential to ensure performance and stability of applications. One of the most critical resources is memory, as both RAM and swap directly influence the system's ability to handle simultaneous processes. The free command has become a standard and fast tool to get a real-time memory snapshot. In this article we will explore its operation, the most useful options and how to interpret your data to make informed decisions in server and workstation management.

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 the 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 first Linux kernel, where the need to monitor memory led to a light utility that could be used by both administrators and developers to debugging performance problems.

Syntax and main options

The basic command syntax is: free [options]. No options, free shows the memory in kilobytes. The most common options include:

  • -b, -bytes:shows values in bytes.
  • -k, -kilobytes:sample in kilobytes (default).
  • -m, -megabytes:sample in megabytes.
  • -g, -gigabytes:sample in gigabytes.
  • -h, -human:presents data with automatically readable units (e.g. 1.2G, 45M).
  • -s:update the output each specified number of seconds.
  • -c:repeat the display a certain number of times before finishing.
  • -t, -total:adds a row that shows the total RAM plus swap.
  • -lo, -low:omit the buffers / cache column for a simpler view.

These options allow the output to be adapted to the needs of the moment, either for rapid review or for continuous monitoring.

Interpretation of the exit

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

Total used free shared buff / cache availableMem: 8056744 3421128 2745600 123456 1889016 38900Swap: 2097148 0 2097148

Each column has a specific meaning:

  • Total:total amount of memory available (RAM or swap).
  • used:memory currently in process use and kernel.
  • free:completely unused memory.
  • shared:memory used by temporary file systems (tmpfs) and other compartments.
  • buff / cache:memory used by the kernel for input / output buffers and file cache; this memory can be released quickly if necessary.
  • Available:estimate how much memory is really available to launch new applications without using the swap, considering that part of the bug / cache can be reused.

The Swap row indicates how much of the exchange space is occupied; a high use of Swap can point to memory pressure and possible performance degradation.

Practical examples

Some examples of daily use:

  1. See the memory in legible format:

    free -h

    Output:

    Total used free shared buff / cache availableMem: 7.8G 3.3G 2.6G 120M 1.8G 3.7GSwap: 2.0G 0B 2.0G
  2. Monitor every 5 seconds for 30 seconds:

    free -s 5 -c 6

  3. Show only the total RAM plus swap:

    free -t

  4. Get values in megabytes without decimals:

    free -m

  5. Combine options for a quick report:

    free -h -t

These commands can be included in monitoring scripts or in tools like watch to create custom control panels.

Tips for administrators

  • Use free -h to get a quick and legible view during routine reviews.
  • Combine free with tools such as top, htop or vmstat to correlate memory use with CPU activity and processes.
  • Set alert thresholds: If the 'available' field falls below 20% of the total RAM, consider reviewing the processes that consume more memory.
  • Remember that a high amount of memory in buff / cache is normal and beneficial; do not interpret it as wasted memory.
  • In virtual environments, check that the guest's assigned swap is sufficient; a constant swap may indicate that the host is overloaded.
  • Document the free baseline values in your infrastructure to detect memory-use growth trends over time.

Conclusion

The free command remains one of the simplest and most effective ways to inspect the RAM and the Linux swap. Its clear output, format options and low resource consumption make it essential for both experienced system managers and users who want to understand the behavior of their machines. Dominar free allows you to detect memory bottle necks, plan hardware updates and maintain optimal performance in any Linux environment.

This work is under aCreative Commons License Attribution 4.0 International for Francesc Roig francesc @ vivaldi.net.

EnglishenEnglishEnglish