Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

free

Show the use of memory (RAM) and swap.

Level
Everyday Linux
Group
Processes and jobs
Needs root
No
Package
procps-ng

What it does

free -h prints total, used and free memory, the shared memory, the buffers and cache, and available: the memory programs can still get (free + cache the kernel can give back). Look at "available", not "free" — Linux uses spare RAM as cache on purpose.

How to write it

free [OPTION]...

Options 17

Most used

-h, --human
Readable units (Mi, Gi).
-b, --bytes
In bytes.
-k, --kibi
In KiB (default).
-m, --mebi
In MiB.
-g, --gibi
In GiB.
--tebi, --pebi
In TiB or PiB.
--kilo, --mega, --giga, --tera, --peta
Powers of 1000 (implies --si).
--si
Use 1000 instead of 1024.
-w, --wide
Buffers and cache in their own columns.
-t, --total
Add a total line (RAM + swap).
-l, --lohi
Low and high memory details.
-L, --line
Everything on one line.
-v, --committed
Show committed memory.
-s, --seconds DELAY
Repeat every DELAY seconds.
-c, --count COUNT
Repeat COUNT times.
--help
Show help.
-V, --version
Show the version.

Examples 10

$ run as a normal user# run as root (or with sudo)

  1. 1Memory in readable units

    free -h
                   total        used        free      shared  buff/cache   available
    Mem:           3.6Gi       812Mi       2.1Gi        12Mi       891Mi       2.6Gi
    Swap:          4.0Gi          0B       4.0Gi

    available = what new programs can still use.

  2. 2Wide view

    free -hw

    Buffers and cache apart.

  3. 3Watch every 2 seconds

    free -h -s 2

    Ctrl+C to stop.

  4. 4With a total line

    free -ht

    RAM + swap together.

  5. 5Value for a script

    free -m | awk '/^Mem:/ {print $7}'
    2662

    Available MiB.

  6. 6One line

    free -hL

    Short for logs.

  7. 7Is swap used a lot?

    free -h | grep Swap; vmstat 1 5

    High si/so in vmstat = the system swaps actively (too little RAM).

  8. 8Drop the cache for a test (not in production)

    sync; echo 3 > /proc/sys/vm/drop_caches; free -h

    Shows that cache is given back.

  9. 9Who uses the memory?

    ps -eo pid,rss,cmd --sort=-rss | head

    free shows totals; ps shows the processes.

  10. 10Check OOM killer events (security/stability)

    journalctl -k | grep -i 'out of memory'

    The kernel killed a process because memory was full.

Files

/proc/meminfo
The source of the numbers.

Exit codes

0 :: Done. 1 :: Error.

Full manual

This page explains the command in simple words. The original manual has every detail.

In your terminal: man free