When your Linux drive starts filling up and you need to know exactly what’s taking the space, the ncdu command is the tool I reach for. NCurses Disk Usage (ncdu) scans your filesystem and shows an interactive view of every directory and file sorted by size. It’s fast, it runs in any terminal, and it lets you delete stuff without leaving the interface. If you manage servers or just run a desktop Linux machine, you’ll use this tool constantly.
1. Running a Basic Scan with the ncdu Command
To start scanning, point the ncdu command at any directory on your system:
ncdu /home/username
ncdu walks through the directory tree and counts up the size of every file. When the scan finishes, you get a sorted list. The biggest directories sit at the top. Small ones sit at the bottom. It’s that simple.
If you run the ncdu command without a path, it scans the current directory. I do this constantly when I notice my root partition dropping below 10 GB. A single run shows me what happened in seconds.
2. Navigating the Interface
ncdu uses a keyboard-driven ncurses interface. No mouse, no GUI, no web dashboard. Just the terminal and your arrow keys. Here are the controls you need:
- Arrow keys / j and k: move up and down the list
- Enter: open a directory and drill into it
- Backspace: go back to the parent directory
- q: quit ncdu
- ?: show the full help screen with every key binding
The interface is responsive even on massive filesystems. I’ve run the ncdu command on a 4 TB NAS share and it handled the scan in under 30 seconds. The navigation stays snappy regardless of how many files you have.
3. Sorting by Directory Size
ncdu sorts everything by size by default. The biggest directories appear first, which is what you want when hunting for space hogs. Press s to toggle between sorting by size and sorting by name.
I keep mine on size sorting. That’s the whole point of a disk usage tool. You want to find the largest directories fast, and the default sort does exactly that.
ncdu also shows the percentage each directory uses relative to the total. This helps you decide where to focus your cleanup effort. A directory using 40% of your disk is a better target than ten directories using 2% each.
4. Deleting Files and Folders
This is where the ncdu command leaves plain du in the dust. You can delete files and directories from inside the interface:
- d: mark the selected item for deletion
- Type yes when ncdu asks for confirmation
- The item disappears from the list and from your disk
ncdu asks for confirmation before deleting anything. That safety net has saved me more than once. I accidentally selected the wrong directory one time and ncdus prompt made me stop and double-check before I hit confirm.
Deleted files go straight to the trash, so theyre recoverable if you act fast. But the ncdu command also supports a secure delete mode with the --permanent-delete flag if you want to skip the trash entirely.
5. Exporting Scan Results with the ncdu Command
You can save a scan to a JSON file for later analysis. Use the -o flag with the ncdu command:
ncdu -o /tmp/scan.json /home/username
This writes the entire directory structure and file sizes to a file. No rescanning needed the next time you open it. I use this for weekly disk audits on my servers. I run the ncdu command every Sunday, save the output, and compare the JSON files to track which directories keep growing.
The JSON format is plain text, so you can parse it with other tools if you want to build reports. ncdu itself can read it back with the import feature.
6. Importing Saved Scan Results
Load a saved scan with the -f flag:
ncdu -f /tmp/scan.json
The interface behaves exactly the same as a live scan. Browse directories, sort by size, check percentages. You can even delete files from an imported scan if the filesystem is still mounted and accessible.
This is useful for comparing snapshots. Run the ncdu command on day one and save the output. Run it again a month later and save again. Load both into ncdu side by side in different terminal tabs and see what changed.
7. Scanning Remote Directories with the ncdu Command
ncdu doesnt have a built-in SSH client, but you can pipe a remote scan through SSH easily:
ssh user@server ncdu -o- / | ncdu -f-
This streams the remote filesystem scan directly into your local ncdu interface. You browse and manage the remote servers files as if they were local. No need to SSH in separately.
I run this on all my cloud servers. A single shell command pipes the remote ncdu command output to my local terminal, and I can clean up logs, cache directories, and old backups from one window.
8. Refreshing the Scan
After you delete something inside ncdu, the interface updates automatically. But if the filesystem changes externally while ncdu is open, press Ctrl+R to rescan.
The rescan is incremental. ncdu only re-reads directories that changed instead of starting from scratch. Thats a big time saver on large filesystems with millions of files.
9. Setting a Minimum Display Size
On a full filesystem, ncdu shows hundreds of entries. Use the -q flag to set a minimum size threshold:
ncdu -q /
Small files and directories below the threshold get filtered out. The output stays clean and focused on the real space hogs. I use this on my root partition where cache files and temp directories create a long tail of tiny entries that clutter the view.
10. Using Color Schemes
ncdu supports a dark color scheme with the --color dark flag:
ncdu --color dark /home/username
The dark scheme is easier on the eyes during long terminal sessions. ncdu also respects your terminals native colors if you prefer not to pass any flags. The interface is minimal by design, so color is really just a personal preference thing.
Why I Keep Coming Back to the ncdu Command
There are other disk usage tools that do similar things. Tools like dust and duf serve the same niche. But ncdu gives you an interactive experience that the others dont. You scan, browse, sort, and delete without ever leaving the terminal.
ncdu is packaged for every major Linux distribution. Install it with apt, dnf, or pacman and it works immediately. The official ncdu page is at dev.yorhel.nl/ncdu and the ncdu man page covers every option in detail. There’s also a useful Baeldung walkthrough on ncdu usage if you want more examples.
If you manage Linux systems or just run out of disk space more often than you’d like, the ncdu command is one of those utilities you’ll wonder how you lived without. It’s simple, it’s fast, and it does exactly one thing well.