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
Nothing matches this filter.
Examples 10
$ run as a normal user# run as root (or with sudo)
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.0Giavailable = what new programs can still use.
2Wide view
free -hwBuffers and cache apart.
3Watch every 2 seconds
free -h -s 2Ctrl+C to stop.
4With a total line
free -htRAM + swap together.
5Value for a script
free -m | awk '/^Mem:/ {print $7}' 2662Available MiB.
6One line
free -hLShort for logs.
7Is swap used a lot?
free -h | grep Swap; vmstat 1 5High si/so in vmstat = the system swaps actively (too little RAM).
8Drop the cache for a test (not in production)
sync; echo 3 > /proc/sys/vm/drop_caches; free -hShows that cache is given back.
9Who uses the memory?
free shows totals; ps shows the processes.
10Check OOM killer events (security/stability)
journalctl -k | grep -i 'out of memory'The kernel killed a process because memory was full.
Nothing matches this filter.
Files
/proc/meminfo- The source of the numbers.
Exit codes
0 :: Done. 1 :: Error.