All technical articles

Finding Heavy Directories with du and ncdu When a Server Disk Fills Up

A quick guide to locating the directories and files that fill a Linux disk using du, sort and ncdu.

Finding Heavy Directories with du and ncdu When a Server Disk Fills Up

When df says the disk is full, the next step is to find where the space went. du reports directory sizes and ncdu does the same interactively.

1. List the heaviest directories

The -x option stops du from crossing into other filesystems so the result stays consistent with df:

du -xh --max-depth=1 /var | sort -rh | head -n 10

2. Interactive use of ncdu

ncdu scans a path and lets you step into directories with the arrow keys. If it is missing, install it from your distribution and run it only on the suspect path:

ncdu -x /var

3. Space used but invisible

If the du total does not match df, a file may have been deleted while a process still holds it open. lsof lists such files, after which you can restart the owning service.

lsof +L1

4. Illustrative example, not a measurement

Suppose (an invented figure) the log directory under /var holds about 30 GB. Read the files and fix log rotation before deleting, rather than wiping blindly.

5. Common mistakes

  • Running du on / without -x.
  • Deleting an active log file instead of truncating it or configuring logrotate.
  • Ignoring inodes when space is free but the disk reports full.

6. Frequently asked questions

Why do du and df disagree? Deleted-but-open files, snapshots and reserved blocks cause the difference.

Is ncdu safe on a live server? The scan uses I/O; run it on a limited path outside peak hours.

7. Quick checklist

  1. Check df -h first.
  2. Run du -xh on the suspect path.
  3. Use ncdu if needed.
  4. Check lsof +L1 for deleted-but-open files.

If you need help reviewing performance or maintaining a server, see the server management services.

More server and WordPress guides are collected in the article archive.

Official references

GNU coreutils du manual · ncdu project page