Linux free Command: Checking Memory Usage and Reading used and available

Test environmentDebian familyDebian 12regular account

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     1811932
free -h
               total        used        free      shared  buff/cache   available
Mem:           954Mi       706Mi        71Mi        19Mi       434Mi       248Mi
Swap:          2.3Gi       630Mi       1.7Gi

In 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.

FieldMeaning (the /proc/meminfo field in parentheses)
totalTotal memory (MemTotal, SwapTotal)
usedMemory in use or not usable. The formula differs by procps version
freeMemory not used for anything (MemFree, SwapFree)
sharedMemory used mostly by tmpfs (Shmem)
buff/cacheSum of kernel buffers and page cache (Buffers + Cached + SReclaimable)
availableEstimate 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     1811932

used 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/meminfo
MemTotal:         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 kB
free -k
               total        used        free      shared  buff/cache   available
Mem:          977836      721596       72644       20476      446800      256240
Swap:        2457596      645664     1811932

In 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        1769
free -g
               total        used        free      shared  buff/cache   available
Mem:               0           0           0           0           0           0
Swap:              2           0           1

Mi 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.7Gi
free -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        1769

The options are gathered in the two tabs below.

OptionCopyDescription
-h, --humanPrints in human-readable units (Ki, Mi, Gi). 1024-based
-k, --kibiPrints in KiB. The default unit when no option is given
-m, --mebiPrints in MiB. Drops the decimal part
-g, --gibiPrints in GiB. Drops the decimal part
--si1000-based units instead of 1024
-w, --wideSplits buff/cache into two columns, buffers and cache
-t, --totalAdds a Total line that sums memory and swap
-l, --lohiAdds Low and High memory lines
-s, --secondsNPrints again every N seconds
-c, --countNPrints N times and then exits
OptionCopyDescription
-b, --bytesPrints in bytes
--kiloPrints in kilobytes. 1000-based
--megaPrints in megabytes. 1000-based
--gigaPrints in gigabytes. 1000-based
--teraPrints in terabytes. 1000-based
--tebiPrints in TiB
-V, --versionPrints 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.

free Command Simulatorfree · user account
[root@server work]#
Use the ↑↓ keys to recall commands you typed earlier.

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.7Gi

Giving -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 0
free: seconds argument `0' is not positive number
echo $?
1

🔢 FAQ & Recommended Content

Divide used by total. In the [free] output on the test server, 723444 ÷ 977836 × 100 was about 74.0%. To use the same basis regardless of procps version, calculate (total - available) ÷ total.

The free output from procps-ng 3.3 on AlmaLinux 9 and procps-ng 4.0 on Debian 12 had no such line. Check the actual free memory, excluding cache, in the available column.

free is part of the procps package. Running [rpm -qf /usr/bin/free] on AlmaLinux 9 returned the procps-ng package.

ℹ️ 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Prove your humanity: 4   +   9   =