How to Check Memory Usage in Linux

When troubleshooting system or application slowdown or misbehavior, one of the first things to check is the system memory usage.
This article explains how to check RAM usage in Linux using several different commands.
Quick Reference
| Command | Description |
|---|---|
free -h | Show memory usage in human-readable format |
free -m | Show memory usage in megabytes |
free -g | Show memory usage in gigabytes |
free -s 5 | Refresh memory stats every 5 seconds |
cat /proc/meminfo | Show detailed memory information |
sudo ps_mem | Show per-program RAM usage |
free Command
free
is the most commonly used command for checking the memory usage of a Linux system. It displays information about the total, used, and free memory.
The most common flags are -h (human-readable), -m (megabytes), and -g (gigabytes).
To print memory usage in human-readable format:
free -h total used free shared buff/cache available
Mem: 3.8Gi 1.1Gi 246Mi 130Mi 2.5Gi 2.4Gi
Swap: 0B 0B 0BTo show memory in megabytes:
free -m total used free shared buff/cache available
Mem: 3906 1087 251 130 2567 2427
Swap: 0 0 0To show memory in gigabytes:
free -g total used free shared buff/cache available
Mem: 3 1 0 0 2 2
Swap: 0 0 0Because -g rounds values down to whole gigabytes, small amounts of free memory can appear as 0 even when some memory is still available. Use free -m or free -h for a more precise view.
Here is what each column means:
- total - The total amount of memory that can be used by the applications.
- used - Used memory. It is calculated as:
used = total - free - buffers - cache - free - Free / Unused memory.
- shared - This column can be ignored; it is shown only for backward compatibility.
- buff/cache - The combined memory used by the kernel buffers and page cache and slabs. This memory can be reclaimed at any time if needed by the applications.
- available - An estimate of the memory that is available for starting new applications, without swapping.
The free command prints information for the physical memory and the system swap
.
top Command
top is a command-line utility that displays real-time information about the running processes. It also shows the system summary, including memory usage.
To invoke the command simply type top:
topThe output will look something like this:

The header of the output includes information about the system’s total, free, and used physical and swap memory.
The %MEM column provides information about the used share of the available physical memory for each running process.
/proc/meminfo
The simplest way to check the RAM memory usage is to display the contents of the /proc/meminfo virtual file. This file is used by the free, top, ps
, and other system information commands.
Use less
or cat
to view the contents of the /proc/meminfo file:
cat /proc/meminfoThe file includes a large amount of information about the system memory and swap usage:
MemTotal: 4030592 kB
MemFree: 401804 kB
MemAvailable: 2507504 kB
...The information from the /proc/meminfo file can be parsed and used in shell scripts.
ps_mem Script
ps_mem
is a Python script that reports per-program RAM memory usage. It works with both Python 2 and 3. On Ubuntu 23.04 and later, install it with pipx to avoid conflicts with the system Python environment:
pipx install ps_memOn older systems, you can use pip3:
sudo pip3 install ps_memRunning ps_mem requires administrator privileges:
sudo ps_memThe output will include the memory usage of each running program in ascending order:
Private + Shared = RAM used Program
...
11.9 MiB + 20.2 MiB = 32.1 MiB nginx (4)
8.2 MiB + 42.4 MiB = 50.6 MiB systemd-journald
55.8 MiB + 307.2 MiB = 363.0 MiB php-fpm7.4 (6)
233.9 MiB + 234.0 MiB = 467.9 MiB redis-server
578.2 MiB + 578.6 MiB = 1.1 GiB mysqld
---------------------------------
2.2 GiB
=================================This script is useful when you want to find out which running program is taking most of your system memory.
Troubleshooting
Why does Linux show very little free memory?
Linux uses unused RAM for buffers and page cache to speed up the system. This memory is shown in buff/cache but can be reclaimed when applications need it. Look at the available column instead of only free.
Why does free -g show 0 GB free?
The -g option rounds values down to whole gigabytes. If less than 1 GiB is free, the column shows 0. Use free -m or free -h for more precise output.
Installed RAM does not match the total shown by Linux
A small portion of physical memory is reserved by the kernel, firmware, integrated graphics, or hardware devices. That is why the reported total can be slightly lower than the RAM installed in the system.
FAQ
What is the difference between free and available in free output?free is the amount of completely unused memory. available is an estimate of how much memory can be used for new applications without swapping — it includes memory that is currently used for buffers and cache but can be reclaimed quickly.
Why does Linux show very little free memory?
Linux uses spare memory for disk caching to speed up file access. This memory shows in the buff/cache column but is freely available to applications when needed. The available column gives a more accurate picture of usable memory.
How do I check the memory usage of a specific process?
Use ps
with the --pid flag: ps -o pid,rss,comm -p <pid>. The rss field shows the resident set size in kilobytes. For a broader view of all processes, sudo ps_mem groups by program name.
How do I check swap usage?
The free command shows swap usage in the Swap: row. To see swap file details and usage per process, use swapon --show.
Conclusion
We have shown you several commands that you can use to check the system memory usage in Linux. The free command is the quickest option for an overview, /proc/meminfo gives the most detail, and ps_mem is useful for tracking down which program is consuming the most RAM.
For a related tool that monitors memory and other resources in real time, see the top command guide
.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page