Operations 8 min read

12 Essential Linux Commands to Monitor Memory Usage

This guide presents twelve practical Linux techniques—from basic commands like free and top to advanced tools such as Grafana with Prometheus—enabling administrators to comprehensively track memory consumption, identify bottlenecks, and maintain system stability and performance.

Liangxu Linux
Liangxu Linux
Liangxu Linux
12 Essential Linux Commands to Monitor Memory Usage

1. free command

The free utility displays total, used, and free memory, along with buffers/cache and swap information. free -h Sample output:

total        used        free      shared  buff/cache   available
Mem:           7.7G        3.1G        1.1G        1.2G        3.5G        2.3G
Swap:          2.0G          0B        2.0G

2. top command

The top command provides a real‑time view of system resources, including memory, CPU, and process activity. top Sample output excerpt:

Tasks: 257 total,   1 running, 256 sleeping,   0 stopped,   0 zombie
%Cpu(s):  1.0 us,  0.7 sy,  0.0 ni, 98.3 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem :   7818.7 total,   1174.9 free,   3291.9 used,   3352.0 buff/cache
MiB Swap:   2048.0 total,   2048.0 free,      0.0 used.   4183.2 avail Mem

3. vmstat command

The vmstat tool reports virtual memory statistics, including processes, CPU, and I/O. vmstat 1 5 Sample output:

procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 1  0      0 1221008 330940 922332    0    0     0     1   13   19  0  0 100  0  0

4. sar command

The sar utility collects and reports performance data for memory, CPU, and disks. sar -r Sample output:

08:10:01 PM kbmemfree kbavail kbmemused %memused kbbuffers kbcached kbcommit %commit kbactive kbinact kbdirty
08:20:01 PM   1259828  4397864   2285128   29.36   248272   3015904   2381884   15.59   2404508   2014540   52

5. /proc/meminfo file

Reading /proc/meminfo provides detailed kernel‑exposed memory metrics. cat /proc/meminfo Sample excerpt:

MemTotal:        7818180 kB
MemFree:         1207196 kB
MemAvailable:   4115164 kB
Buffers:           329540 kB
Cached:           2884056 kB
SwapCached:            0 kB

6. pmap command

The pmap command shows a process's memory map, including address ranges, permissions, and sizes. pmap PID Sample output excerpt:

0000559b7ffac000   2060K r-x-- /usr/bin/bash
0000559b801cb000    244K r--s- /usr/lib/locale/locale-archive
...

7. smem command

smem

presents memory usage in a more readable format and can sort by process. smem Sample output excerpt:

PID User   Command                     Swap   USS   PSS   RSS
    1 root   /sbin/init                    0%   0%   0.01% 0.01%
    2 root   [kthreadd]                    0%   0%   0%    0%
 2135 user   /usr/bin/firefox              0%   0.51% 1.46% 3.13%

8. atop command

atop

is an interactive system monitor offering detailed resource statistics. atop Sample output excerpt:

ATOP - myhostname          2022/01/01   08:00:01           10s elapsed
  PR  VIRT  RES  SHR S  CPU% MEM%   TIME+  COMMAND
   1  2500  456  312 S   0.0  0.0   0:00.01 bash

9. htop command

htop

provides a colorful, interactive alternative to top with easier navigation.

htop

10. glances command

glances

is a cross‑platform monitoring tool that aggregates CPU, memory, disk, network, and more, and supports plugins.

glances

11. Grafana + Prometheus

Combining Grafana with Prometheus creates a powerful open‑source stack for visualizing memory metrics and setting alerts.

12. Custom scripts

Administrators can write bespoke scripts that invoke the above commands or read files under /proc to collect, process, and display memory data tailored to specific needs.

By mastering these twelve approaches, you can obtain a complete picture of Linux memory consumption, quickly pinpoint resource bottlenecks, and keep systems running efficiently.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

monitoringMemorySystem Administrationcommands
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.