Linux·5 min read·

Monitoring Disk Usage and Inodes: df, du, and ncdu

Use df, du, and ncdu to find what is consuming disk space and track inode usage before your VPS runs out.

NB

Netbay Developer Relations

Netbay Engineering

On this page

Disk space running out is one of the most common emergency calls in server administration. But full disk is not the only failure mode. A filesystem can be full because of small files exhausting its inode table, even when there is plenty of free space. Understanding both df and du, plus the interactive ncdu, turns a storage panic into a quick diagnosis.

df: Filesystem and Inode Overview

The df command reports filesystem space usage. The human-readable form is:

bash
df -h
df -h /
df -ih /

The first lists every mounted filesystem with sizes in human units. The second focuses on the root filesystem. The third shows inode usage: the -i flag swaps space columns for inode columns. If the IUse% column shows 100 percent, you are out of inodes even though df -h might show free space.

Inodes are the filesystem records that hold a file's metadata. Each file or directory consumes one. A temporary directory filled with millions of tiny files can exhaust the inode table while using very little disk space.

du: Measure Directory Sizes

The du command sums the disk usage of a directory tree:

bash
du -sh /var/www
du -h --max-depth=1 / | sort -h
du -sh /var/log/* | sort -h | tail -20

-s summarizes, -h is human-readable. The second command lists each top-level directory and sorts by size to find what is consuming the disk. The third ranks log subdirectories by size.

To find the largest individual files:

bash
find / -type f -size +500M -exec ls -lh {} \; 2>/dev/null
du -a / | sort -rn | head -20

The first finds files larger than 500 megabytes. The second reviews the entire tree by size. Combine these to locate the heaviest consumers in seconds.

ncdu: Interactive Disk Usage Explorer

ncdu gives an interactive, terminal-based view of disk usage with a navigable tree. Install it with your package manager:

bash
apt install ncdu
dnf install ncdu
apk add ncdu

Then run it against a directory:

bash
ncdu /var
ncdu -x /

The -x flag prevents crossing filesystem boundaries, which keeps the scan inside one disk. Within ncdu you navigate with arrow keys, press d to delete a file or directory, and press q to quit.

Cleaning Up Common Culprits

System logs, package caches, and old kernels are frequent offenders. Clean them safely:

bash
journalctl --vacuum-size=100M
apt autoremove --purge
dnf clean all
find /var/log -name "*.gz" -mtime +90 -delete

journalctl --vacuum-size=100M trims the systemd journal to about 100 megabytes. apt autoremove --purge removes orphaned packages. The find line deletes compressed logs older than 90 days.

Setting Up Alerting

Prevention beats reaction. A simple cron job warns you before the disk fills:

bash
df -h / | awk 'NR==2 { if (gsub(/%/,"",$5) > 90) print "Disk nearly full" | "mail -s alert admin@example.com" }'

On a Netbay VPS, combine disk-usage scripts with your own monitoring or a lightweight external uptime check to catch problems early.

Disk Usage Diagnosis Flow Write fails df -h / Space full? du -sh / ncdu Inodes full? df -ih / du -h --max-depth=1 find largest dirs ncdu / interactive navigation find -size +500M largest files Clean: journalctl --vacuum, apt autoremove, remove old logs Prevent: cron alert when usage exceeds 90%

Takeaway

Check both space and inodes with df, drill into culprits with du and ncdu, and clean up system caches and logs regularly. Monitor disk usage on a Netbay Linux VPS with high-speed SSD storage at netbayhosts.in.

Keep reading

Follow along on a real VPS

Deploy Linux in under 60 seconds

These guides are written against Ubuntu, Debian, and RHEL-family images — the same ones on NetBay.

Deploy an instance