$devvkit learn --librarie ncdu-&-duf-guide
ncdu & duf Guide
[disk][storage][cli][analysis]
System Monitoring
Install
sudo apt install ncdu duf brew install ncdu duf # Windows: ncdu via WSL; duf has a Windows release
ncdu (NCurses Disk Usage) scans a directory and presents an interactive, sortable view of disk usage. Arrow through the tree, delete files directly with `d`, refresh with `r`. Perfect for answering "what's filling up my disk?" on a server.
duf is a modern `df` alternative — colored output, human-readable sizes, and categorization (local, fuse, special, network, etc.). Unlike `df`, duf highlights over-full filesystems and shows inode usage too.
ncdu tricks: press `-` to go to parent directory, `g` to show percentage bar, `b` to toggle between apparent size and disk usage (including sparse files). For GUI, use Baobab (GNOME Disk Usage Analyzer) or WinDirStat (Windows).
ncdu Basics
Scan directory— Analyze disk usage.
ncdu /home # Scan specific directory ncdu / # Scan entire filesystem (slow) ncdu -x / # Don't cross filesystem boundaries ncdu -q # Quiet mode (faster on slow disks)
ncdu export/import— Save scan for later.
ncdu -o scan.json /home # Export scan to JSON file ncdu -f scan.json # Import and browse saved scan # Scan once, analyze many times: great for remote-mounted drives
ncdu Navigation
ncdu keyboard shortcuts— Navigate efficiently.
# Arrow keys / hjkl: navigate # d: delete selected file/dir (ask confirmation) # n: sort by name / s: sort by size # g: toggle percentage bar # b: toggle apparent/disk size # r: rescan current directory # i: show item info # t: toggle between dir/file view # -: go to parent # q: quit # /: search
ncdu delete— Free space interactively.
# Navigate to large directory, press d # Confirm deletion with yes # Safer than rm -rf because you see sizes before deleting # Great for cleaning: node_modules, .cache, old logs
duf
duf basic— Disk free summary.
duf # All mounts (with colors!) duf -only local # Only local filesystems duf -only network,fuse # Remote + FUSE mounts duf -only tmpfs # Temp filesystems duf -hide-fs tmpfs # Hide temporary filesystems
duf custom theme— Output formatting.
duf --theme dark # Dark mode duf --theme light # Light mode duf --style=unicode # Fancy output duf --style=ascii # CI-safe output duf --json # JSON for scripts # Custom columns: duf --output mountpoint,size,used,avail,usage,inodes
Scripting
Find large directories— Script for big space hogs.
# List top 20 directories by size:
du -h /var 2>/dev/null | sort -rh | head -20
# Or with ncdu JSON export:
ncdu -o - / 2>/dev/null | jq '[.[] | select(._type == "dir" and .name != "/")] | sort_by(.asize) | reverse | .[:20] | .[] | {name: .name, size: .asize}'