hosting

How to check disk space usage in Linux

3 min read
How to check disk space usage in Linux

Running out of disk space on a Linux server can crash services, corrupt databases, and cause all kinds of hard-to-debug problems — catching it early starts with knowing which commands to run and what the output actually means.

Check Overall Disk Space with df

The df command (disk free) is the fastest way to see how much space is used and available across all mounted filesystems. Always use the -h flag to get human-readable sizes:

df -h

You'll get output that looks something like this:

Filesystem      Size  Used Avail Use%  Mounted on
/dev/vda1        50G   18G   30G  38%  /
tmpfs           2.0G     0  2.0G   0%  /dev/shm
/dev/vda2       100G   72G   28G  72%  /var

Here's what each column means:

  • Filesystem — the device or partition (on VPS servers you'll typically see vda or sda devices)
  • Size — total capacity of that partition
  • Used — space currently consumed
  • Avail — space you can actually write to
  • Use% — the number to watch; anything above 85–90% is worth investigating
  • Mounted on — where that partition lives in the directory tree

To see inode usage (relevant when you have millions of small files), add the -i flag:

df -ih

A filesystem can run out of inodes while still showing free space — which causes the same "no space left on device" errors as a full disk.

Find What's Eating Your Disk with du

Once df tells you which partition is full, du (disk usage) helps you find what is filling it up. To check the total size of a specific directory:

du -sh /var/log

The -s flag gives you a single summary total instead of listing every subdirectory, and -h keeps it human-readable.

To find the largest directories inside a path, run:

du -h --max-depth=1 /var | sort -rh | head -20

This lists the top 20 largest items one level deep inside /var, sorted by size. Swap in any directory you want to investigate. Run it recursively at different levels to drill down to the offending folder.

A Faster Alternative: ncdu

If you spend a lot of time tracking down disk usage, ncdu is worth installing. It's an interactive, ncurses-based disk usage browser that lets you navigate directories with arrow keys:

# Ubuntu/Debian
sudo apt install ncdu

# CentOS/AlmaLinux/RHEL
sudo dnf install ncdu

ncdu /

It scans the filesystem and gives you a sorted, browsable view — much faster than running du repeatedly by hand.

Common Gotcha: The Disk Shows Full But You Can't Find the Files

This is one of the most common head-scratchers on Linux servers. You run du -sh /* and the numbers don't add up to what df reports as used. The most likely cause: a running process has an open file handle on a deleted file. The space isn't released until the process closes or restarts.

Find deleted files still held open by running:

sudo lsof | grep deleted

You'll see output listing the process, PID, and the size of the deleted-but-still-open file. The fix is to restart the offending service. For example, if it's nginx holding a large deleted log file:

sudo systemctl restart nginx

After restarting, the file handle is released and the disk space is recovered. You'll see df -h reflect the freed space immediately.

Quick Reference: Commands to Know

  • df -h — overall disk space by partition
  • df -ih — inode usage by partition
  • du -sh /path — total size of a specific directory
  • du -h --max-depth=1 /path | sort -rh | head -20 — largest subdirectories
  • sudo lsof | grep deleted — find deleted files still consuming space
  • ncdu / — interactive disk usage browser

Start with df -h to identify the full partition, then use du or ncdu to drill into what's consuming the space. Most disk space problems on Linux come down to runaway logs, leftover backups, or core dump files — and all of them show up clearly once you know where to look.

✏️ Edit This Post