LinuxCommandLibrary

free

Display amount of free and used memory

TLDR

Display system memory

$ free
copy

Display memory in Bytes/KB/MB/GB
$ free -[b|k|m|g]
copy

Display memory in human-readable units
$ free [[-h|--human]]
copy

Refresh the output every 2 seconds
$ free [[-s|--seconds]] [2]
copy

SYNOPSIS

free [options]

PARAMETERS

-b
    Display the amount of memory in bytes.

-k
    Display the amount of memory in kilobytes (default).

-m
    Display the amount of memory in megabytes.

-g
    Display the amount of memory in gigabytes.

-t
    Display the total for each of the lines.

-h
    Show all output fields automatically scaled to smallest unit
and print the units of measure in the header.

-H
    Same as -h, but use powers of 1000 not 1024.

-w
    Wide output. Use this option if the device names are long.

-s <delay>
    Continuously display the free command output every <delay> seconds.

-c <count>
    Display the free command output <count> times.

--si
    Use powers of 1000 not 1024 for display.

--mebi
    Display the values in mebibytes.

--gibi
    Display the values in gibibytes.

--tebi
    Display the values in tebibytes.

--pebi
    Display the values in pebibytes.

-V
    Display version information and exit.

--help
    Display help text and exit.

DESCRIPTION

The free command provides a quick overview of memory usage on a Linux system. It displays the total amount of physical and swap memory, as well as the amount of memory used, free, buffered, and cached. This information is crucial for monitoring system performance and identifying potential memory bottlenecks. The command reads memory usage statistics from the /proc/meminfo file. The output can be adjusted with options to display values in bytes, kilobytes, megabytes, gigabytes, terabytes, or petabytes. It can also show the output continuously refreshing at specified intervals. A key aspect is understanding the 'available' memory, which represents an estimate of how much memory is available for starting new applications, without swapping. The cached memory represents a combination of disk caches and shared memory. By default, memory is shown in kibibytes.

CAVEATS

The 'available' memory metric is an estimation provided by the kernel. It might not perfectly reflect the actual memory available to new processes due to various kernel optimizations and fragmentation. Swapping can significantly impact performance and is not reflected directly in 'available'.

UNDERSTANDING CACHED MEMORY

Cached memory refers to the memory used by the kernel for caching data from disk. This improves system performance by reducing the need to read data directly from slower storage devices. Cached memory can be quickly released and reused by applications if needed.

BUFF/CACHE VS. AVAILABLE

The 'Buff/Cache' column represents the memory used for buffers and cache, while 'available' is an estimation of how much memory is available for starting new applications, without swapping. Understanding both is crucial for memory analysis.

HISTORY

The free command has been a standard utility in Unix-like operating systems for many years. It provides a simple and effective way to monitor memory usage. Over time, enhancements have been added to support different units of measurement and improve the accuracy of memory reporting. Development focused on providing a clear, concise, and readily understandable view of memory usage to system administrators.

SEE ALSO

vmstat(8), top(1), htop(1), slabtop(1), proc(5)

Copied to clipboard