System and users
free
Show how much RAM and swap is in use, free, and available to new programs.
free [-h|-m|-g] [-w] [-t] [-s SECONDS [-c COUNT]]
free summarizes /proc/meminfo into a small table: total memory, what processes use, what
the kernel holds as page cache and buffers, and what is left. The column to read is
available, not free. Linux deliberately fills idle RAM with cached file data and gives it
back the moment a program asks, so a low free figure on a healthy server is normal.
available is the kernel's own estimate of how much memory a new workload could get without
swapping.
Numbers are in kibibytes unless you pick a unit; -h chooses one per value and is what you
want interactively. For scripts, use a fixed unit (-m, -b) and pick the column with awk,
or read MemAvailable from /proc/meminfo directly.
The examples run in a container, which sees the host machine's memory, so the totals are large.
Examples
Show memory use in kibibytes
free
total used free shared buff/cache available Mem: 263772776 168448804 32880560 127516 64872520 95323972 Swap: 8388604 2131428 6257176
One row for RAM, one for swap. buff/cache is reclaimable cache; available is roughly
free plus the part of that cache the kernel can drop, which is why it is far larger than
free.
Show memory in readable units
free -h
total used free shared buff/cache available Mem: 251Gi 160Gi 31Gi 124Mi 61Gi 90Gi Swap: 8.0Gi 2.0Gi 6.0Gi
-h picks a unit per value and suffixes it: Gi, Mi and so on are powers of 1024. This
is the form to type at a prompt.
Use a fixed unit for comparison
free -m
total used free shared buff/cache available Mem: 257590 164526 32083 124 63352 93063 Swap: 8191 2081 6110
-m prints whole mebibytes in every cell, so values line up and stay parseable. -g uses
gibibytes, but rounds small values down to 0, which hides detail.
Use powers of 1000 instead of 1024
free -h --si
total used free shared buff/cache available Mem: 270G 172G 33G 130M 66G 97G Swap: 8.6G 2.2G 6.4G
With --si the suffixes become G and M and mean 10^9 and 10^6 bytes, matching how disk
and RAM vendors label capacity. Without it, free uses binary units.
Split buffers and cache into separate columns
free -wh
total used free shared buffers cache available Mem: 251Gi 160Gi 31Gi 124Mi 2.9Gi 59Gi 90Gi Swap: 8.0Gi 2.0Gi 6.0Gi
-w (wide) shows buffers (block-device metadata) and cache (file contents) separately
instead of the combined buff/cache column.
Add a total line for RAM plus swap
free -ht
total used free shared buff/cache available Mem: 251Gi 160Gi 31Gi 124Mi 61Gi 90Gi Swap: 8.0Gi 2.0Gi 6.0Gi Total: 259Gi 162Gi 37Gi
-t appends a Total: row that sums the memory and swap rows.
Sample memory a few times
free -h -s 1 -c 3
total used free shared buff/cache available
Mem: 251Gi 160Gi 31Gi 124Mi 61Gi 90Gi
Swap: 8.0Gi 2.0Gi 6.0Gi
total used free shared buff/cache available
Mem: 251Gi 161Gi 30Gi 124Mi 61Gi 90Gi
Swap: 8.0Gi 2.0Gi 6.0Gi
total used free shared buff/cache available
Mem: 251Gi 161Gi 30Gi 124Mi 61Gi 90Gi
Swap: 8.0Gi 2.0Gi 6.0Gi -s 1 repeats the report every second and -c 3 stops after three reports, each followed
by a blank line. Without -c it runs until you press Ctrl-C.
Get available memory as a number for a script
free -m | awk '/^Mem:/ { print $7 }'
92505
The seventh field of the Mem: line is available in mebibytes. Matching the row label
rather than taking "line 2" keeps this working if other rows are added.
Read the same figures from /proc/meminfo
grep -E '^(MemTotal|MemFree|MemAvailable|SwapTotal)' /proc/meminfo
MemTotal: 263772776 kB MemFree: 32649300 kB MemAvailable: 95092828 kB SwapTotal: 8388604 kB
This file is where free gets its data, in kB. It has dozens more fields (dirty pages,
huge pages, slab) when you need detail free does not show.
Print everything on one line
free -L
SwapUse 2131428 CachUse 64872644 MemUse 168655796 MemFree 32673452
-L puts swap used, cache used, memory used and memory free on a single line (in KiB),
handy for appending to a log with a timestamp.
Common pitfalls
Treating the
freecolumn as headroom. Cache counts as used but is handed back on demand; watchavailable, and worry when it is low and swap activity (si/soinvmstat) is high.free -grounds down, so a machine with 900 MiB available shows0. Use-hor-mwhen the numbers are small.Inside a container
freereports the host's memory, not the container's cgroup limit. Check/sys/fs/cgroup/memory.maxfor the limit that will actually trigger the OOM killer.Old procps versions printed a
-/+ buffers/cacheline instead ofavailable. Advice that tells you to read that line predates procps 3.3.10.
GNU vs BSD and macOS
The examples above ran the GNU/Linux version. These are the differences that matter on macOS and the BSDs (written from their documentation, not run here).
freeis Linux-only (procps); macOS has nofreecommand. Usevm_statthere, which reports page counts rather than bytes, ortop -l 1 | headfor a summary.
Options worth knowing
A selection, described in our own words. For the full list, see free(1) or free --help.
| Option | What it does |
|---|---|
-h, --human | Show each value with a readable unit suffix. |
-b, --bytes | Show values in bytes. |
-k, --kibi | Show values in kibibytes (the default). |
-m, --mebi | Show values in mebibytes. |
-g, --gibi | Show values in gibibytes, rounded down. |
--si | Use powers of 1000 instead of 1024. |
--mega | Show values in megabytes (10^6 bytes). |
--giga | Show values in gigabytes (10^9 bytes). |
-w, --wide | Show buffers and cache in separate columns. |
-t, --total | Add a row with RAM and swap totals. |
-L, --line | Print a compact single-line summary. |
-l, --lohi | Show low and high memory statistics. |
-v, --committed | Show committed memory and the commit limit. |
-s, --seconds N | Repeat the report every N seconds. |
-c, --count N | Stop after N reports. |
-V, --version | Print the procps version and exit. |
Related
vmstatReport processes, memory, swap, I/O and CPU activity, once or at a regular interval.topShow a live, sorted view of processes and system load; batch mode prints snapshots for logs and scripts.uptimeShow how long the system has been running, how many users are logged in, and the load averages.psPrint a snapshot of running processes, with the columns, filters and sort order you choose.duShow how much disk space files and directories use, totalled per directory.dfReport how much space is used and free on mounted filesystems.