Blog
3 min read

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 with docker system df. (Docker Commands Cheat Sheet)
  • /var/lib/postgresql — your database (don't delete this!).
  • Backups or uploads stored on the same disk.
  • node_modules and 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 prune removes 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 -h for how full, du/ncdu for what's using it.
  • Memory: free -h and watch available, not free.
  • Processes: top/htop, or ps 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