Bash Memory Usage
Learn how to check RAM and swap usage on Linux with the free command and its -h human-readable flag.
Reading Memory with free
The free command reads live memory statistics from the kernel and prints a snapshot: total installed RAM, how much is used, how much is free, and the state of swap space. It is one of the fastest ways to answer whether a machine is running low on memory.
Example
$ free
total used free shared buff/cache available
Mem: 8144316 3211840 612204 184032 4320272 4522108
Swap: 2097148 0 2097148Those numbers are in kilobytes, which is why 8144316 doesn't immediately read as 8 gigabytes. The -h flag rewrites every column in human-readable units. It also helps to know what each column means: free is memory doing nothing at all, while buff/cache is memory the kernel is using for disk caching and will hand back instantly if an application needs it. available is the realistic number, showing how much memory a new process could actually get right now.
Example
$ free -h
total used free shared buff/cache available
Mem: 7.8Gi 3.1Gi 598Mi 180Mi 4.1Gi 4.3Gi
Swap: 2.0Gi 0B 2.0GiWatching Memory Change Over Time
free takes a single snapshot by default, but the -s flag repeats the report every N seconds, turning it into a lightweight monitor you can leave running in a terminal while reproducing a memory issue. Press Ctrl+C to stop.
Example
$ free -h -s 2
total used free shared buff/cache available
Mem: 7.8Gi 3.2Gi 520Mi 180Mi 4.1Gi 4.2Gi
Swap: 2.0Gi 0B 2.0Gi
total used free shared buff/cache available
Mem: 7.8Gi 3.4Gi 402Mi 180Mi 4.0Gi 4.0Gi
Swap: 2.0Gi 12Mi 2.0Gi- -h prints sizes in human-readable units
- -s N repeats the report every N seconds
- -t adds a Total row combining Mem and Swap
- -w splits buffers and cache into separate columns
- -c N repeats exactly N times, then stops