Mastering Disk Usage Analysis With ncdu

As a systems engineer, understanding disk usage is not just beneficial — it's essential for maintaining the health and performance of your servers. In this guide, we’ll explore how to efficiently analyze your filesystem using ncdu along with a few other reliable command-line tools.

What is ncdu?

ncdu (NCurses Disk Usage) is a lightweight, interactive disk usage analyzer.
It gives you a fast and easy way to identify which directories and files are hogging your disk space — all through a simple terminal interface.

Installing ncdu

Getting ncdu up and running is quick:

On Debian/Ubuntu-based systems:

sudo apt install ncdu

On Red Hat/CentOS/Fedora systems:

sudo yum install ncdu

Using ncdu to Analyze Filesystem Usage

Running ncdu is super straightforward — just point it at a directory:

ncdu /path/to/directory

Restricting to a Single Filesystem

One of ncdu's killer features is the -x option, which restricts the scan to a single filesystem:

ncdu -x /var/log

This is really handy when you want to avoid crossing into mounted volumes or other partitions accidentally.

Navigating the ncdu Interface

When you launch ncdu, you can interact with it using your keyboard:

  • Arrow keys: Navigate through the directories

  • Enter: Dive into a directory

  • d: Delete a file or directory (⚠️ use carefully)

  • q: Quit the program

It’s intuitive enough that you’ll be flying through your filesystem in minutes.

Alternative Tools for Disk Usage Analysis

While ncdu is amazing for interactive exploration, the good old command line has some other tricks up its sleeve.

1. df — Display Free Disk Space

The df command shows you disk space usage and free space across all mounted filesystems:

df -h

The -h flag makes it human-readable (i.e., shows sizes in KB, MB, GB).

To focus on a specific directory:

df -h /var

2. du — Estimate File and Directory Sizes

The du command is perfect for quick checks:

du -sh /var/log
  • -s: Display only the total size

  • -h: Human-readable format

Want a breakdown of subdirectories?

du -h --max-depth=1 /var/log | sort -hr

This will show you the size of each immediate subdirectory, sorted from largest to smallest.

3. find — Locate Large Files

Sometimes you just need to hunt down the big files:

find /var -type f -size +100M -exec ls -lh {} \; | sort -k5 -hr

This finds files larger than 100MB and lists them, sorted by size.

When to Use Each Tool

ToolBest Use Case
ncduInteractive exploration and cleanup
dfQuick snapshot of disk space across filesystems
duDetailed file/directory size summaries (great for scripting)
findLaser-targeted search for huge files

Conclusion

Keeping an eye on your disk usage is essential for any serious server management strategy.
ncdu is an awesome tool for interactive, detailed analysis — especially when paired with options like -x to stay within boundaries.
But don't sleep on the classics either: df, du, and find each bring their own strengths to your sysadmin toolkit.

By combining these tools, you’ll stay ahead of disk space problems before they turn into full-blown outages. 🚀

0
Subscribe to my newsletter

Read articles from Nhật Trường directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Nhật Trường
Nhật Trường

Let explore DevOps, Security, and Tech insights with me. You're about to dive headfirst into my tech brain dump-expect spicy takes on best practice 💻 🚀