>_cmd.script

free

Display system memory usage: RAM and swap

System

By CMD Script Team · 4 min read · Last updated

SYNTAX
free [OPTIONS]

Options

Command options and flags
FlagDescription
-hPrint sizes in human-readable units (KiB, MiB, GiB) rather than raw kilobytes
-mPrint sizes in mebibytes
-gPrint sizes in gibibytes
-sRepeat output continuously every N seconds, e.g. free -s 2
-tAdd a total line summing physical memory and swap together
-cRepeat output N times (combine with -s to limit the number of refreshes)

Distribution compatibility

  • Ubuntu
  • Debian
  • Fedora
  • Arch
  • macOS (not available; use vm_stat or top instead)

What it does

free displays a snapshot of the system's memory usage: total, used, free, shared, buff/cache, and available RAM, plus swap usage, all sourced from /proc/meminfo. It's the fastest command-line way to check whether a Linux system is under memory pressure, though correctly reading its output requires understanding the difference between "free" and "available" memory.

Beginner examples

  • free — show memory usage in kilobytes
  • free -h — show memory usage in human-readable units (KiB/MiB/GiB)
  • free -m — show memory usage in megabytes
  • free -t — add a combined total line for memory + swap
free -h

Advanced examples

  • Monitor memory usage live, refreshing every 2 seconds: free -h -s 2
  • Limit a live monitor to 5 refreshes: free -h -s 2 -c 5
  • Check swap usage specifically to see if the system has started swapping under pressure: look at the Swap: row's used column
  • Script an alert when available memory drops below a threshold: free -m | awk '/^Mem:/{if ($7 < 500) print "low memory!"}'
  • Compare available vs free to understand real memory headroom on a busy server.
free -m | awk '/^Mem:/{print "Available: " $7 " MB"}'

Common mistakes

  • Panicking over a low number in the free column while ignoring available — Linux intentionally uses spare RAM for disk cache (shown in buff/cache), which is reclaimed instantly when applications need it.
  • Interpreting high swap used values in isolation — some swap usage is normal and can persist even after memory pressure eases, since the kernel doesn't always swap pages back in until they're touched again.
  • Forgetting that older versions of free (pre-procps 3.3.10) don't have an available column at all, making used/free harder to interpret correctly on very old systems.
  • Comparing raw byte counts across systems without normalizing units — always use -h, -m, or -g for consistent, readable comparisons.

Tips

  • Trust the available column, not free, when deciding whether a system is actually low on memory.
  • Use free -h -s 2 as a lightweight live memory monitor when htop/top isn't installed or is overkill for a quick check.
  • Pair free with vmstat 1 when diagnosing whether high memory usage correlates with active swapping (look at si/so columns in vmstat).

Best practices

  • Build memory alerting around the available column, not free, to avoid false alarms caused by normal disk cache usage.
  • When investigating a suspected memory leak, track used and available over time (e.g. with free -s) rather than relying on a single snapshot.
  • Always specify a unit flag (-h, -m, or -g) in documentation or scripts so output is unambiguous across different free versions and locales.

Try it yourself

A simulated shell with a sample home directory — experiment freely, nothing leaves your browser. Type help to list supported commands.

Real-world use cases

  • Quickly diagnosing whether an application slowdown is caused by memory exhaustion.
  • Checking whether a server has started swapping heavily, which can severely degrade performance.
  • Deciding whether a VM or container needs a memory limit increase based on sustained available memory being low.
  • Including a memory snapshot in incident reports or capacity-planning documentation.

Common interview questions

  • What's the difference between "free" and "available" memory in free's output? "Free" is completely unused memory; "available" is an estimate of memory that can be given to new applications without swapping, including reclaimable cache/buffers — "available" is the more meaningful number in practice.
  • Why does a healthy Linux server often show very little in the free column? Because Linux uses spare RAM for disk cache/buffers to speed up I/O, and that memory is instantly reclaimable — it's not wasted or leaked.
  • How would you monitor memory usage continuously from the command line? free -h -s <seconds> refreshes the report at the given interval; -c can cap the number of refreshes.

Frequently Asked Questions

What's the difference between 'free' and 'available' memory in the output?

The free column shows memory that is completely unused and idle. The available column is a smarter estimate of memory that could be made available to new applications without swapping, since it accounts for memory the kernel can quickly reclaim from cache/buffers. In practice, available is the number you should trust when judging if a system is low on memory.

Why does free show almost no 'free' memory even on an idle server?

Linux aggressively uses spare RAM for disk cache and buffers to speed up file access, since that memory is instantly reclaimable when applications need it. This is normal, healthy behavior, not a memory leak — check the available column instead of free for the real picture.

How do I get free to refresh automatically like a live monitor?

Use free -s N to repeat the report every N seconds, e.g. free -h -s 2 refreshes a human-readable report every 2 seconds until you press Ctrl+C; add -c to limit the number of refreshes.

Cheat sheet

Download a quick-reference cheat sheet for free.