Linux free Command: Checking Memory Usage and Reading used and available
The Linux free command reads the memory information collected by the kernel and prints the total, used, and free amounts of memory and swap. When free was run on a Debian 12 test server, used 706Mi turned out to be total minus available, and plugging the same numbers into the AlmaLinux 9 free formula shrank used to 449Mi, which confirmed that each version counts used differently.
The output below was produced under a regular account on the Debian 12 test server, and the account name in the simulator is an example value.
1️⃣ How to Use the Linux free Command and Read Its Output
Running free with no options prints memory (Mem) and swap (Swap) in KiB. The numbers are long, so adding -h shortens them to Mi and Gi units that are easier to read.
free total used free shared buff/cache available
Mem: 977836 723444 73136 20472 444452 254392
Swap: 2457596 645664 1811932free -h total used free shared buff/cache available
Mem: 954Mi 706Mi 71Mi 19Mi 434Mi 248Mi
Swap: 2.3Gi 630Mi 1.7GiIn the -h output, the Mem line shows 706Mi in use out of 954Mi in total, and the memory that can be allocated to new programs (available) was 248Mi. The meaning of each column is in the table below.
| Field | Meaning (the /proc/meminfo field in parentheses) |
|---|---|
| total | Total memory (MemTotal, SwapTotal) |
| used | Memory in use or not usable. The formula differs by procps version |
| free | Memory not used for anything (MemFree, SwapFree) |
| shared | Memory used mostly by tmpfs (Shmem) |
| buff/cache | Sum of kernel buffers and page cache (Buffers + Cached + SReclaimable) |
| available | Estimate of memory available for starting new programs without swapping (MemAvailable) |
2️⃣ How free Calculates used and available
With only 71Mi in the free column it is easy to conclude that memory is running out, but the kernel uses spare memory as file cache and reclaims that cache when a program asks for memory. So to see how much more can be used, look at the available column. On this server free was 71Mi, but available was 248Mi.
The formula for used differs by procps version. procps-ng 4.0 in Debian 12 calculates used as [total - available], and procps-ng 3.3 in AlmaLinux 9 calculates it as [total - free - buffers - cache].
With -w, buffers and cache were split into separate columns and printed in KiB.
free -w total used free shared buffers cache available
Mem: 977836 723444 73136 20472 10648 433804 254392
Swap: 2457596 645664 1811932used 723444 was equal to total 977836 minus available 254392. Plugging the same numbers into the procps 3.3 formula gives 977836 - 73136 - 10648 - 433804 = 460248, which makes used about 449Mi.
The numbers in free come from /proc/meminfo. We pulled the same fields with grep and then ran free -k right away.
grep -E "^(MemTotal|MemFree|MemAvailable|Buffers|Cached|SwapCached|SwapTotal|SwapFree|Shmem|SReclaimable):" /proc/meminfoMemTotal: 977836 kB
MemFree: 72644 kB
MemAvailable: 256240 kB
Buffers: 10752 kB
Cached: 389264 kB
SwapCached: 134232 kB
SwapTotal: 2457596 kB
SwapFree: 1811932 kB
Shmem: 20476 kB
SReclaimable: 46784 kBfree -k total used free shared buff/cache available
Mem: 977836 721596 72644 20476 446800 256240
Swap: 2457596 645664 1811932In free -k, free 72644 and available 256240 matched MemFree and MemAvailable in /proc/meminfo. If you set a memory alert on used, the number changes when the procps version changes, so to watch the same value regardless of version, set the alert on available.
3️⃣ free Command Options and Units
-m prints in MiB and -g in GiB, dropping anything after the decimal point. The same memory was printed as 954 with -m and as 0 with -g.
free -m total used free shared buff/cache available
Mem: 954 706 71 19 434 248
Swap: 2399 630 1769free -g total used free shared buff/cache available
Mem: 0 0 0 0 0 0
Swap: 2 0 1Mi and Gi in -h are 1024-based units, and adding --si switches to 1000-based units. The same total came out as 954Mi with -h and as 1.0G with --si.
free -h --si total used free shared buff/cache available
Mem: 1.0G 740M 74M 20M 455M 260M
Swap: 2.5G 661M 1.9G-w splits the buff/cache column into two columns, buffers and cache, and -t adds a Total line that sums memory and swap.
free -h -w total used free shared buffers cache available
Mem: 954Mi 706Mi 71Mi 19Mi 10Mi 423Mi 248Mi
Swap: 2.3Gi 630Mi 1.7Gifree -h -t total used free shared buff/cache available
Mem: 954Mi 706Mi 71Mi 19Mi 434Mi 248Mi
Swap: 2.3Gi 630Mi 1.7Gi
Total: 3.3Gi 1.3Gi 1.8Gi-l adds Low and High memory lines. On this server, the High line was all 0.
free -m -l total used free shared buff/cache available
Mem: 954 706 71 19 434 248
Low: 954 883 71
High: 0 0 0
Swap: 2399 630 1769The options are gathered in the two tabs below.
| Option | Copy | Description |
|---|---|---|
| -h, --human | Prints in human-readable units (Ki, Mi, Gi). 1024-based | |
| -k, --kibi | Prints in KiB. The default unit when no option is given | |
| -m, --mebi | Prints in MiB. Drops the decimal part | |
| -g, --gibi | Prints in GiB. Drops the decimal part | |
| --si | 1000-based units instead of 1024 | |
| -w, --wide | Splits buff/cache into two columns, buffers and cache | |
| -t, --total | Adds a Total line that sums memory and swap | |
| -l, --lohi | Adds Low and High memory lines | |
| -s, --secondsN | Prints again every N seconds | |
| -c, --countN | Prints N times and then exits |
| Option | Copy | Description |
|---|---|---|
| -b, --bytes | Prints in bytes | |
| --kilo | Prints in kilobytes. 1000-based | |
| --mega | Prints in megabytes. 1000-based | |
| --giga | Prints in gigabytes. 1000-based | |
| --tera | Prints in terabytes. 1000-based | |
| --tebi | Prints in TiB | |
| -V, --version | Prints version information |
🔲 free Command Simulator
The simulator below calculates free from a single snapshot of memory values on the same test server. The chips hold the options run in this post, and giving -s without -c prints twice and then stops as if Ctrl+C had been pressed.
4️⃣ Checking Swap and Repeating Output with the Linux free Command
The Swap line shows usage of the swap space set aside on disk. When memory runs short, the kernel moves part of the memory contents to swap, and because swap lives on disk it is slower to read and write than memory. This server was using 630Mi out of 2.3Gi of swap.
To watch whether used and Swap grow, set an interval with -s and print again. -s 2 -c 3 printed three times at 2-second intervals and exited, and from the second output on, used dropped from 706Mi to 704Mi.
free -h -s 2 -c 3 total used free shared buff/cache available
Mem: 954Mi 706Mi 71Mi 19Mi 434Mi 248Mi
Swap: 2.3Gi 630Mi 1.7Gi
total used free shared buff/cache available
Mem: 954Mi 704Mi 70Mi 19Mi 436Mi 250Mi
Swap: 2.3Gi 630Mi 1.7Gi
total used free shared buff/cache available
Mem: 954Mi 704Mi 70Mi 19Mi 436Mi 250Mi
Swap: 2.3Gi 630Mi 1.7GiGiving -s without -c keeps printing until you press Ctrl+C. Giving an interval of 0 printed an error message, and the exit code was 1.
free -s 0free: seconds argument `0' is not positive numberecho $?1🔢 FAQ & Recommended Content
Linux · System
Linux uptime command
How to use uptime to check server uptime and the load averages for the last 1, 5, and 15 minutes.
Linux · Processes
ps command
Options and usage examples of the ps command, which lists the processes currently running.
ℹ️ Affiliate Disclosure
This site's content contains affiliate links. When a visitor buys a product or service through one of them, the site receives a commission from the seller. The amount the buyer pays(it goes down during event discounts ↓)does not go up. Posted prices, discounts, and stock reflect the time of writing and may differ, so confirm with the seller before buying. Products are chosen and reviewed by our own standards, and commissions do not affect the order or content of reviews.