The VikiD Truth

Knowledge base / Computing

Computing | computingFreedom | Build | Picolisp | Picolisp Machine | pil sources | Linux | BASH | C Programmming | Operating Systems | Javascipt | Emacs | vim | Pharo Smalltalk | Computer Security | Python | Tools to Learn

NCDU

The truth about a full disk is that it is almost never “everything, a little bit”. It is usually one or two forgotten directories eating most of the space. ncdu is the tool that points straight at them.

What it is, in plain words

ncdu (NCurses Disk Usage) is a terminal program that scans a directory tree, adds up how much space everything takes, and then lets you walk the result interactively: biggest things at the top, arrow keys to dive in, d to delete. It is du with eyes.

There are two lines of it today:

Both look and feel the same.

Why it matters

When a disk fills up, things break in strange ways: builds fail, databases refuse writes, your package manager half-installs an update, logins stall because the shell can’t write history. The usual reflex – df -h – tells you that a disk is full but not why. du -sh * tells you why, one level at a time, slowly. ncdu scans once and then answers every “where did it go?” instantly.

An everyday analogy: the overflowing wardrobe

Your wardrobe won’t close. You could fold every single shirt a little tighter, or you could open it and notice the three winter coats and the box of old cables taking up half the space. ncdu opens the wardrobe and lines everything up by size, so the coats are the first thing you see.

A hands-on example

Install it:

sudo xbps-install -S ncdu      # Void Linux / Vikix
sudo pacman -S ncdu            # Arch / Manjaro
sudo apt install ncdu          # Debian / Ubuntu

Scan your home directory:

ncdu ~

Scan the whole root filesystem without crossing into other mounts (so it doesn’t wander into /proc, network shares or USB drives):

sudo ncdu -x /

Inside the browser:

KeyDoes
↑ ↓ / j kmove
→ / Enteropen directory
←go up
ddelete selected (asks first)
s / nsort by size / name
gtoggle percentage/graph
eshow hidden/excluded files
iinfo about the item
rrescan
qquit

Typical culprits you’ll find in seconds: ~/.cache (browsers, pip, npm, Zig, Go), old node_modules, container images in /var/lib/docker or ~/.local/share/containers, old kernels, /var/log, and the package cache (/var/cache/xbps on Void, /var/cache/pacman/pkg on Arch).

Scanning remote or huge machines

ncdu can save a scan to a file and load it later, which is perfect for servers:

# On the server: scan and export (no UI)
sudo ncdu -x -o /tmp/root.ncdu /

# Or stream it straight to your laptop and browse there
ssh myserver 'sudo ncdu -x -o- /' | ncdu -f-

For read-only browsing where you don’t want to delete by accident, add -r (read-only) or -rr (also disables the shell spawn).

How it works underneath

flowchart LR
  A[walk tree<br/>stat every file] --> B[sum sizes<br/>per directory]
  B --> C[sort children]
  C --> D[ncurses UI]
  D -- delete --> A

It calls stat() on every file and adds up the disk usage (blocks actually allocated), not the apparent size. That distinction matters: a sparse VM image may say 100 GB in ls -l but use 5 GB on disk. Press a in ncdu to toggle between apparent size and disk usage. Hard-linked files are counted once and marked H.

Common misconceptions

Connections

ncdu check free disk space linux

Last edited · 2 revisions

Tags: #Computing