ncdu, dust, gdu and du on one 30 GB Mac folder: 3 seconds or 23, and why the totals differ
We ran du, ncdu, dust and gdu on the same 30 GB folder, twice each, on one Mac. The times split into two groups (3 to 4 seconds against 23), and the totals split into disk usage against apparent size, which is a 1.5 GiB difference you should understand before trusting any of them.
The setup
The folder was a projects directory of about 700,000 files, roughly 30 GB, on an internal SSD with 10 CPU cores. Tools from Homebrew: ncdu 2.9.2, dust 1.2.7, gdu 5.39.0 (installed as gdu-go to avoid a name clash with coreutils). Each ran twice, so the second run had a warm file cache.
Speed
| Tool | Run 1 | Run 2 | Notes |
|---|---|---|---|
du -sk | 22.5 s | 22.6 s | one thread |
du -sAk | 25.5 s | 22.8 s | one thread |
ncdu 2.9.2, default | 23.5 s | 22.8 s | one thread by default |
ncdu -t 8 | 3 s | eight threads, same scan | |
dust 1.2.7 | 3.8 s | 3.5 s | multi-threaded |
gdu 5.39.0 | 4.1 s | 3.3 s | multi-threaded |
The warm cache did not help much: this is limited by walking 700,000 directory entries, not by reading data. What helped was threads. ncdu was as slow as du until we passed -t 8, then it matched dust and gdu. If you use ncdu, set -t (or put it in ~/.config/ncdu/config).
Accuracy: the totals
| Tool | Reported | Which size? |
|---|---|---|
du -sk | 31,420,508 KB = 29.96 GiB | disk blocks used |
du -sAk | 29,870,038 KB = 28.49 GiB | apparent (sum of file lengths) |
ncdu export | 31,650,188 KB = 30.18 GiB disk, 29,871,397 KB apparent | both, in the JSON |
dust | 29Gi (rounded down; 29.96 GiB fits) | disk blocks |
gdu | 29.9 and 30.0 GiB on two runs | disk blocks |
So the tools agree within about 0.2 GiB, but only if you compare like with like:
- Disk usage vs apparent size is a 1.5 GiB gap here. Many small files probably each occupy a whole 4 KiB block, so disk usage is larger than the sum of lengths. On a folder of compressed apps we copied, it went the other way:
du -sk2,066,588 KB vsdu -sAk2,251,321 KB, because macOS stores many app files compressed. - ncdu was 229 MB (0.7%) above du in both runs. We did not find out why (hard links and directory blocks are possible), so treat sub-1% gaps between tools as noise.
- Run-to-run drift of a few hundred KB on a live folder (du 31,420,508 then 31,420,796) is files being written while scanning.
Where they should disagree, and where we tested
| Case | What to expect | Tested? |
|---|---|---|
| APFS clones | every tool counts each clone in full, like du does | yes, see the [clone article](https://zofle.com/articles/apfs-clone-files-du-double-count-cp-c-free-space-measured.html): du was 400 MiB high on 800 MiB used |
| Compressed files (apps) | disk usage below apparent | yes, above |
| Online-only iCloud/Drive files | apparent size counts files that are not on disk; disk usage should not | not tested: our test Mac had under 60 KB there |
| Symlinks | du does not follow them; tools differ in options | not tested |
Which one to use
- Quick look at where the space went:
gduorncdu -t 8, both interactive. Pressdin ncdu ordin gdu to delete, but only on folders you have already checked. - A one-line answer in scripts:
du -sk(always present, same totals as the others). - A picture of the biggest folders in the terminal:
dust. - Anything you will compare to free space: use disk usage, never apparent size, and compare with
df -kas in the clone article.
If you would rather not use Terminal at all, Zofle shows the same breakdown as categories on the Mac. For the usual suspects in a developer's folder, read developer caches that fill your disk.
Zofle shows your Mac storage by category and lets you move big, old files to the Trash with Undo, so you can see what is worth the effort before you run any command.
Download Zofle for MacZofle Pro news
People signing up now will get Zofle Pro, with more features, for free when we launch it.