Linux free command


The free command in Linux is used to display the amount of free and used memory in the system, including physical RAM and swap space. It provides a snapshot of the memory usage on your system and is commonly used for quick checks on system resources.

Basic Syntax:

free [options]

Commonly Used Options:

  • -h: Human-readable format (displays memory in KB, MB, or GB).
  • -m: Display memory in megabytes (MB).
  • -g: Display memory in gigabytes (GB).
  • -t: Show the total memory (including physical and swap memory).

Basic Usage:

free

Sample Output:

total used free shared buff/cache available Mem: 8.0Gi 1.7Gi 3.8Gi 234Mi 2.4Gi 5.6Gi Swap: 2.0Gi 0B 2.0Gi

Output Explanation:

  1. Mem: - The physical RAM (Random Access Memory) usage.

    • total: Total amount of RAM in the system (e.g., 8.0Gi).
    • used: RAM currently used by processes (e.g., 1.7Gi).
    • free: RAM that is completely free and unallocated (e.g., 3.8Gi).
    • shared: Memory used by the tmpfs (temporary filesystem) or shared memory (e.g., 234Mi).
    • buff/cache: Memory used by the kernel buffers and cache (e.g., 2.4Gi).
    • available: An estimate of how much memory is available for starting new applications without swapping (e.g., 5.6Gi).
  2. Swap: - The swap space usage.

    • total: The total swap space available (e.g., 2.0Gi).
    • used: The amount of swap space currently in use (e.g., 0B).
    • free: The remaining swap space that is not used (e.g., 2.0Gi).

Example with -h option (human-readable format):

free -h

Sample Output:

total used free shared buff/cache available Mem: 8.0Gi 1.7Gi 3.8Gi 234Mi 2.4Gi 5.6Gi Swap: 2.0Gi 0B 2.0Gi
  • The output shows memory in human-readable format (e.g., Gi for gibibytes and Mi for mebibytes).

Example with -m option (display in megabytes):

free -m

Sample Output:

total used free shared buff/cache available Mem: 8192 1732 3840 240 2432 5732 Swap: 2048 0 2048
  • Here, memory is displayed in megabytes (MB).

Explanation of Columns:

  1. total: The total amount of memory (RAM or swap) available on your system.
  2. used: The amount of memory that is currently in use by running processes.
  3. free: The amount of memory that is completely unused and available for allocation.
  4. shared: The amount of memory used by shared resources like tmpfs.
  5. buff/cache: The memory used by the operating system for buffers and cached data (this memory can be released if needed).
  6. available: The amount of memory that is readily available for new applications without needing to swap.

Swap Memory:

Swap is space on your hard drive used when RAM is full. The system moves inactive pages from RAM to swap to free up memory for active processes. The swap usage can indicate whether your system is running out of RAM and starting to rely on swap, which is slower.

Example with -t option (total memory):

free -t

Sample Output:

total used free shared buff/cache available Mem: 8192 1732 3840 240 2432 5732 Swap: 2048 0 2048 Total: 10240 1732 5888 240 4864 5732
  • Total:: This line includes both physical memory (RAM) and swap space combined.

Summary of Columns in free:

  • Mem:
    • total: Total system memory.
    • used: Memory currently in use by processes.
    • free: Memory that is not being used.
    • shared: Memory being used for shared resources (like tmpfs).
    • buff/cache: Memory used by the kernel buffers and cache.
    • available: Memory that is available for use by new processes (taking cache into account).
  • Swap:
    • total: Total swap space.
    • used: Amount of swap space in use.
    • free: Amount of unused swap space.

Conclusion:

The free command is a simple yet essential tool for checking the memory and swap usage on a Linux system. It gives you an immediate sense of the overall memory usage and helps identify potential memory bottlenecks, especially when combined with other system monitoring tools. The -h, -m, -t, and other options allow you to customize the output for better readability and precision.