Check disk, memory and CPU usage
Commands like df, free and top show how much disk, memory and CPU a Linux server is using, so you can spot problems early.
- Updated Nov 27, 2026
- Markdown
Check disk, memory and CPU on a Linux server and tell if something is running low.
- A Linux server you can reach over SSH
Most outages on a small server are not exotic. To check disk, memory and CPU on a Linux server, run df -h, free -h and uptime. The disk fills up with logs and images, memory runs out and the kernel kills your database, or something eats the CPU and the site crawls. Three commands, run in a minute, tell you which of these it is. Run them when something feels wrong, and also now and then when it does not.
How it works#
Disk, memory and CPU are three separate limited resources, and each fails differently.
Disk is space on a filesystem. A full disk means programs cannot write: databases stop, logs fail and apt breaks. Besides bytes, a filesystem has a fixed number of inodes, one per file. Millions of tiny files can use up inodes before bytes run out.
Memory is where running programs keep data. Linux uses memory that is not needed by programs as a cache for files, so the free column often looks small on a healthy server. The available column estimates what programs could get without swapping. When memory really runs out, the kernel’s out-of-memory killer ends a process. Swap is disk used as slow overflow memory (see add swap space on Ubuntu). A little use is fine, but heavy swapping makes a server crawl.
CPU is measured two ways. Usage is a percentage over a short interval. Load average counts processes that are running or waiting for a CPU, averaged over 1, 5 and 15 minutes. Compare load to the core count: one busy core means a load of about 1 on a 1 core machine, which is full, but only a quarter used on a 4 core machine. Load also counts processes stuck waiting for disk, so a high load with an idle CPU often points at slow storage.
A worked example: a site starts returning errors. You run df -h and see / at 100%. You run sudo du -h --max-depth=1 /var | sort -h and the biggest line is /var/lib/docker. You run docker system df and find that old images take most of it. You free space on purpose, and df -h drops back. The sequence is always the same: confirm, locate, act.
Step 1: Check disk space#
df -h-h prints sizes in human readable units. Look at the Use% column for the line mounted on /.
What you should see: a table with Filesystem, Size, Used, Avail, Use% and Mounted on. Several entries such as tmpfs are in memory and can be ignored.
To find what is using the space inside a folder:
sudo du -h --max-depth=1 /var | sort -h--max-depth=1 lists each subfolder one level down, and sort -h orders human readable sizes. The biggest are at the bottom. Repeat on the largest folder to drill down.
What you should see: a list of sizes and paths ending in the total for /var.
Step 2: Check memory#
free -hRead the available column. It is the memory that programs can still use. The Swap row shows disk space used as emergency memory, and 0B total means no swap is set up.
What you should see: Mem: and Swap: rows with total, used, free, shared, buff/cache and available.
Step 3: Check CPU and load#
nproc
uptimenproc prints the number of CPU cores. uptime prints how long the server has run and three load averages (1, 5 and 15 minutes). If the load stays above the core count, the machine is overloaded.
What you should see: a single number from nproc, then one line from uptime ending with load average: and three values.
Step 4: Watch live usage#
topIt shows the busiest processes first. Press q to quit. Press M to sort by memory and P to sort by CPU. If htop is installed (sudo apt install htop), it gives a friendlier view with colors and scrolling.
What you should see: a header with load, CPU and memory, then a process table that refreshes every few seconds.
Check it worked#
df -hprints a table with a/line and aUse%value.free -hprintsMem:andSwap:rows.nprocprints a single number.topfills the screen with a process list and refreshes every few seconds.
For a one-line summary of the worst offenders, run ps aux --sort=-%mem | head -n 5. It should list the header and the four processes using the most memory.
Edge cases and gotchas#
- Small
freeis normal. A server with 1 GB can show almost nothing free and still be healthy, because the cache will shrink on demand. Look atavailableand at swap activity. - Disk can be full while
dufinds little. A deleted log still takes space while a process keeps it open.sudo lsof +L1lists such files, and restarting the process frees the space. Also trydf -ifor inodes. - Docker uses a lot of disk. Images, stopped containers and build cache live under
/var/lib/docker, andduin other folders will not find them. Usedocker system dfto see them, and read free disk space with docker prune safely. - Containers have their own limits.
freeinside a container may show the host’s memory even when the container is limited. Check the container limits with Docker tools. - A burst is not a trend. One
topsnapshot during a backup can mislead. Compare the 1, 5 and 15 minute load values to see the trend. - Memory shown by
topper process can double count shared memory. Do not add the numbers up. Useavailablefor the overall picture. - Mounted volumes show as separate lines. Data on another disk will not appear under
/. Read theMounted oncolumn. - Reserved blocks mean a full disk at 95%. Some filesystems reserve space for root, so
Availcan reach zero whileUse%is under 100.
Troubleshooting#
| Symptom | Likely cause | Fix |
|---|---|---|
No space left on device | Disk full or out of inodes | Check df -h and df -i, then find the big folder with du |
du: cannot read directory with Permission denied | Your user cannot read some folders | Add sudo |
htop: command not found | Not installed by default | Install with apt or use top |
Processes vanish and the log says Out of memory: Killed process | The kernel killed a process | Add swap, lower memory use or upgrade the plan |
| Load is high but CPU looks idle | Processes wait on slow disk | Check disk use and top for the wa value |
Killed printed by a command | The out-of-memory killer ended it | Same as above, and read journalctl -k |
df: ...: Permission denied | A mount is not readable | Add sudo or ignore that mount |
| Swap is full and the server crawls | Memory use is above RAM | Find the process with top, then add RAM or fix the leak |
Real-world scenario#
Ravi gets an alert that his site is slow. He logs in and runs uptime: the load is 9 on a 2 core server. top shows a backup script using all of the CPU and heavy swap. free -h says available is almost zero.
He kills the script, and the load falls within a minute. Then he reads the script, sees that it compresses the whole database in memory, and changes it to stream to disk. He also adds swap as a safety net.
The three commands told him which resource was the problem. Without them he might have upgraded the plan and not fixed anything.
Quick reference#
| Question | Command |
|---|---|
| How full is the disk | df -h |
| Which folder is big | sudo du -h --max-depth=1 /var | sort -h |
| Are inodes used up | df -i |
| How much memory is available | free -h |
| How many cores | nproc |
| How busy | uptime |
| Who uses memory | ps aux --sort=-%mem | head |
Security and safety notes#
- Do not delete files in
/var/lib,/etcor/usrto free space. Services depend on them. - Do not remove a log file a service has open and expect the space back. Truncate or rotate it instead.
Related lessons#
- Essential Linux commands for servers: the basics used here
- Add swap space on Ubuntu: help for low memory servers
- Free disk space with docker prune safely: reclaim Docker space
- Limit Docker log size: stop logs from filling disks
- Monitor uptime simply: get told before users notice
Next#
Try it: Check your server's health
Look at disk, memory and CPU with the standard commands.
Want a real machine? Free browser labs: Killercoda
Check what you learned
Frequently asked questions
What does a load average of 1.00 mean?
On a machine with one CPU core it means the core was busy all the time. Compare the load to the core count from nproc, because a 4 core machine has room for about 4.
Why does free show little free memory?
Linux uses spare memory as cache, which it gives back when programs need it. Read the available column, not the free column.
The disk shows full but du finds little. Where did the space go?
A deleted file can stay on disk while a process holds it open, or the filesystem can be out of inodes. Check df -i and restart the process that holds the file.
Is high CPU always a problem?
No. A build or backup can use all cores for a while. It is a problem when it stays high with no reason, or when the load stays above the core count.
Keep going: guides and tutorials
- Install a Self-Hosted PaaS on Your Own Server in Five Minutes One installer download, one setup token, one sample app. The full Levelrail install on a fresh Linux server, with the checks and the fixes.
- Manage Secrets Self-Hosted: Env Vars and Master Key Rotation Set env vars and encrypted secrets on a self-hosted server, apply changes safely, and rotate the master key with no downtime without locking yourself out.