free
Display system memory usage: RAM and swap
By CMD Script Team · 4 min read · Last updated
free [OPTIONS]Options
| Flag | Description |
|---|---|
-h | Print sizes in human-readable units (KiB, MiB, GiB) rather than raw kilobytes |
-m | Print sizes in mebibytes |
-g | Print sizes in gibibytes |
-s | Repeat output continuously every N seconds, e.g. free -s 2 |
-t | Add a total line summing physical memory and swap together |
-c | Repeat 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 kilobytesfree -h— show memory usage in human-readable units (KiB/MiB/GiB)free -m— show memory usage in megabytesfree -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'susedcolumn - Script an alert when available memory drops below a threshold:
free -m | awk '/^Mem:/{if ($7 < 500) print "low memory!"}' - Compare
availablevsfreeto 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
freecolumn while ignoringavailable— Linux intentionally uses spare RAM for disk cache (shown inbuff/cache), which is reclaimed instantly when applications need it. - Interpreting high swap
usedvalues 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 anavailablecolumn at all, makingused/freeharder to interpret correctly on very old systems. - Comparing raw byte counts across systems without normalizing units — always use
-h,-m, or-gfor consistent, readable comparisons.
Tips
- Trust the
availablecolumn, notfree, when deciding whether a system is actually low on memory. - Use
free -h -s 2as a lightweight live memory monitor whenhtop/topisn't installed or is overkill for a quick check. - Pair
freewithvmstat 1when diagnosing whether high memory usage correlates with active swapping (look atsi/socolumns invmstat).
Best practices
- Build memory alerting around the
availablecolumn, notfree, to avoid false alarms caused by normal disk cache usage. - When investigating a suspected memory leak, track
usedandavailableover time (e.g. withfree -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 differentfreeversions 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
availablememory 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
freecolumn? 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;-ccan 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.