How to Check Disk Space and Memory Usage on Linux
The commands to see what's using your server's disk and memory: df -h for free disk space, du and ncdu to find big folders, free -h for memory (and why 'free' memory looks low), and top/htop for which process is using RAM and CPU — plus how to clean up safely.
When a server gets slow, an app crashes, or you see "No space left on device", the first questions are: how full is the disk, and how much memory is in use? These commands answer both.
Disk space: df -h
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 75G 61G 11G 85% /
-h means "human-readable" (G and M instead of raw bytes). Look at the Use% for / (the main disk). Above 85–90% is time to clean up; at 100%, databases and apps start failing. (No Space Left on Device)
What's using the disk: du
df tells you the disk is full; du tells you what filled it.
sudo du -h --max-depth=1 / 2>/dev/null | sort -h
That lists the size of each top-level folder, biggest last. Then drill in:
sudo du -h --max-depth=1 /var | sort -h
The usual suspects:
/var/log— logs that never rotate, and the systemd journal./var/lib/docker— old images, stopped containers, build cache. Check withdocker system df. (Docker Commands Cheat Sheet)/var/lib/postgresql— your database (don't delete this!).- Backups or uploads stored on the same disk.
node_modulesand build folders in home directories.
For an interactive view, install ncdu:
sudo apt install ncdu
sudo ncdu /
Use the arrow keys to browse into folders sorted by size.
Memory: free -h
free -h
total used free shared buff/cache available
Mem: 7.6Gi 3.1Gi 420Mi 120Mi 4.1Gi 4.2Gi
Swap: 2.0Gi 0B 2.0Gi
Look at "available", not "free". Linux uses spare memory as a disk cache (buff/cache) to speed things up, and gives it back instantly when programs need it. Low "free" is normal and healthy. Low "available" is the real warning sign.
If swap is heavily used and the server feels sluggish, you're short of memory.
Which process is using what: top and htop
top
Press M to sort by memory, P by CPU, q to quit. htop is a friendlier version with colours and scrolling:
sudo apt install htop
htop
Press F6 to choose the sort column, F9 to send a process a signal, F10 to quit. (Kill a Process in Linux)
A quick one-liner for the top memory users:
ps aux --sort=-%mem | head -n 10
Clean up safely
- Never delete database files by hand. Shrink a database with proper tools. (Postgres VACUUM and Bloat)
- Old logs: compress or delete rotated ones; cap the systemd journal with
sudo journalctl --vacuum-size=500M. - Docker:
docker system pruneremoves stopped containers, unused networks and dangling images (read what it says before confirming). - Package caches:
sudo apt clean.
If memory keeps running out
The kernel's OOM killer will start killing processes — often your app or database. Find the leak, add swap as a buffer, or move to a bigger server. (The Linux OOM Killer, Node.js Memory Leaks)
The summary
- Disk:
df -hfor how full,du/ncdufor what's using it. - Memory:
free -hand watch available, not free. - Processes:
top/htop, orps aux --sort=-%mem.
EasySpawn watches your server's disk and memory for you, and Claude Code can investigate what's filling them and clean up safely when you ask. See how it works or join the waitlist.
Related: Basic Linux Commands · What Is Linux? · Why Is My Website Slow? · CPU Steal Time
Keep reading
"User Is Not in the Sudoers File": What It Means and How to Fix It
"username is not in the sudoers file. This incident will be reported." means your Linux user isn't allowed to run commands as root with sudo. How to add a user to the sudo (or wheel) group from root, edit sudoers safely with visudo, recover when you've locked yourself out, and the safer alternatives to giving out sudo.
"Python Is Not Recognized as an Internal or External Command": How to Fix It
On Windows, "'python' is not recognized as an internal or external command, operable program or batch file" (or "pip is not recognized") means Windows can't find Python on your PATH. How to check whether Python is installed, use the py launcher, add Python to PATH, turn off the Microsoft Store alias, and fix pip.