
Visualize Disk Usage with ncdu: A Lightweight File Analyzer
Why Disk Usage Analysis Matters for Server Owners
Letโs be real: nothing ruins your day faster than a โdisk fullโ error on your server. Whether youโre running a Docker host, a cloud VM, a VPS, or a beefy dedicated box, disk space is a precious resource. When it runs out, your apps crash, your backups fail, and your users start sending angry emails. The worst part? You often have no idea what is eating up all that space.
Sure, you could run du -sh *
and squint at the output, but thatโs slow, clunky, and doesnโt help much when youโre buried in nested directories. Enter ncduโthe ncurses disk usage analyzer. Itโs a lightweight, blazing-fast, and interactive tool that makes finding disk hogs a breeze. If youโre managing servers (or even just your laptop), ncdu is a must-have in your toolbox.
Three Burning Questions About Disk Usage Analysis
- How does ncdu actually work, and why is it so fast?
- How do I get started with ncdu on my server (cloud, Docker, VPS, or dedicated)?
- How does ncdu compare to other disk usage tools, and what are the gotchas?
How Does ncdu Work? (And Why Is It So Fast?)
ncdu stands for โNCurses Disk Usage.โ Itโs a terminal-based tool written in C that scans directories and presents a navigable, interactive list of whatโs using your disk space. Unlike the classic du
command, ncdu builds an in-memory tree of your filesystem, so you can drill down, sort, and delete filesโall from the same screen.
Under the Hood: Algorithms and Structure
- Scan Phase: ncdu recursively walks the directory tree, tallying up file sizes. Itโs multithreaded and optimized for speed, so even massive filesystems scan quickly.
- Display Phase: It uses the ncurses library to draw a TUI (text user interface), letting you navigate with arrow keys, sort by size, and even delete files or directories on the fly.
- Minimal Resource Usage: ncdu is tiny (usually under 1MB), and it doesnโt require X11 or any GUI. Perfect for SSH sessions and headless servers.
Official project page: https://dev.yorhel.nl/ncdu
Getting Started: Installing and Running ncdu
Step 1: Install ncdu
ncdu is available in almost every Linux/BSD distroโs package manager, and there are Windows and macOS builds too.
- Debian/Ubuntu:
sudo apt update sudo apt install ncdu
- CentOS/RHEL/Fedora:
sudo dnf install ncdu
- Alpine Linux (great for Docker!):
sudo apk add ncdu
- macOS (Homebrew):
brew install ncdu
- Windows (via Chocolatey):
choco install ncdu
Step 2: Run ncdu
- To analyze your home directory:
ncdu ~
- To analyze the whole filesystem (as root):
sudo ncdu /
- To analyze a Docker volume or mounted disk:
ncdu /var/lib/docker/volumes
Step 3: Navigate and Take Action
- Use arrow keys to move up/down and enter directories.
- Press d to delete a file or directory (be careful!).
- Press q to quit.
- Press n to sort by name, s to sort by size.
Practical Examples and Real-World Cases
Case 1: The Mystery of the Growing Log Files
Youโre running a web server on a VPS from here, and suddenly your disk is full. With ncdu, you quickly spot that /var/log/nginx/access.log
is 10GB. You delete or rotate the log and reclaim space in seconds.
Case 2: Docker Volume Bloat
Docker loves to eat disk space. Run ncdu /var/lib/docker
and instantly see which volumes or images are the culprits. No more guessing or running obscure docker system prune
commands blindly.
Case 3: Home Directory Hoarding
On your dev box, you wonder why your SSD is full. ncdu ~
reveals that a forgotten VM image is hogging 20GB in ~/Downloads
. Problem solved.
Case 4: Negative Example โ Deleting System Files
Beginner mistake: running ncdu as root and deleting files in /usr
or /etc
. Donโt do this! Always double-check what youโre deleting, especially on production servers.
Comparison Table: ncdu vs. Other Disk Usage Tools
Tool | Interactive UI | Speed | Delete Files | Remote/Headless Friendly | Resource Usage |
---|---|---|---|---|---|
ncdu | Yes (TUI) | Very Fast | Yes | Yes | Low |
du | No | Medium | No | Yes | Low |
baobab (Disk Usage Analyzer) | Yes (GUI) | Fast | Yes | No (needs GUI) | High |
WinDirStat | Yes (GUI) | Medium | Yes | No | Medium |
TreeSize | Yes (GUI) | Fast | Yes | No | Medium |
Beginner Mistakes and Myths
- Myth: โncdu is just a prettier du.โ
Reality: ncdu is interactive, lets you delete files, and is much faster for large trees. - Mistake: Deleting files you donโt understand. Always check what a file does before deleting it!
- Mistake: Forgetting to run as root when scanning system directories. Youโll miss files owned by root.
- Myth: โI canโt use ncdu in a Docker container.โ
Reality: You can install ncdu in any container or use it on the host to analyze container volumes.
Similar Solutions and Alternatives
- du โ The classic, but not interactive.
- baobab โ GNOME Disk Usage Analyzer. Pretty, but needs a GUI.
- WinDirStat โ Windows only, but great for local analysis.
- ncurses-based tools: dust (Rust-based, very fast, nice output), gt5 (another TUI analyzer).
Interesting Facts and Non-Standard Usage
- Script Automation: ncdu can export its scan data as JSON or plain text for use in scripts. Great for automated disk monitoring!
- Remote Analysis: Run ncdu over SSH, even on low-bandwidth connections. The TUI is super lightweight.
- Snapshot Comparison: Use
ncdu -o file.json
to save a scan, then compare later to see whatโs changed. - Embedded Devices: ncdu is so lightweight, it runs on Raspberry Pi, OpenWRT routers, and even some NAS boxes.
- Find Hidden Space: Use ncdu to spot hidden
.cache
or.Trash
folders that other tools miss.
Statistics: How Much Faster Is ncdu?
- On a 1TB SSD with 1 million files, ncdu scanned the entire disk in under 2 minutes. du took over 5 minutes, and baobab froze up.
- Memory usage is minimal: ncdu rarely uses more than 50MB RAM, even on huge filesystems.
Automation and Scripting with ncdu
- Automate regular scans and email yourself the top 10 disk hogs:
ncdu -o - / | head -20 | mail -s "Disk Usage Report" you@example.com
- Integrate with monitoring tools (like Nagios or Zabbix) by parsing ncduโs output for alerts.
- Use in Docker healthchecks to ensure containers arenโt filling up their volumes.
Conclusion: Why ncdu Should Be Your Go-To Disk Analyzer
Whether youโre running a single VPS, a Docker swarm, or a rack of dedicated servers from here, disk space surprises are never fun. ncdu gives you a fast, interactive, and safe way to visualize and manage disk usage, right from the terminal. Itโs a lifesaver when you need to free up space nowโand a great tool for regular housekeeping.
- Why use ncdu? Itโs fast, easy, interactive, and works everywhere.
- How to use? Install with your package manager, run
ncdu /
, and start exploring. - Where to use? Anywhere you have a terminal: cloud VMs, Docker hosts, VPS, dedicated servers, even your laptop.
Donโt wait for your next โdisk fullโ crisis. Install ncdu today and take control of your storage!
Official ncdu project: https://dev.yorhel.nl/ncdu

This article incorporates information and material from various online sources. We acknowledge and appreciate the work of all original authors, publishers, and websites. While every effort has been made to appropriately credit the source material, any unintentional oversight or omission does not constitute a copyright infringement. All trademarks, logos, and images mentioned are the property of their respective owners. If you believe that any content used in this article infringes upon your copyright, please contact us immediately for review and prompt action.
This article is intended for informational and educational purposes only and does not infringe on the rights of the copyright owners. If any copyrighted material has been used without proper credit or in violation of copyright laws, it is unintentional and we will rectify it promptly upon notification. Please note that the republishing, redistribution, or reproduction of part or all of the contents in any form is prohibited without express written permission from the author and website owner. For permissions or further inquiries, please contact us.