Skip to content

How to Analyze and Clean Disk Space on macOS Using `ncdu` and `df`

# 🧹 How to Analyze and Clean Disk Space on macOS Using `ncdu` and `df`
Keeping your macOS system clean and your disk space under control is essential — especially when you're building large projects like Xcode apps or using environments like Node.js. In this post, you'll learn how to inspect, analyze, and free up space using `ncdu` and `df`.
## 📦 Step 1: Install `ncdu` (Disk Usage Analyzer)
`ncdu` (NCurses Disk Usage) is a fast, interactive command-line tool for analyzing disk usage. First, install it via Homebrew:
```bash
brew install ncdu

Use ncdu to recursively analyze your home directory:

Terminal window
ncdu ~

This will launch an interactive UI where you can:

  • Browse hidden files and folders
  • Sort by size
  • Delete files interactively (press d)
  • Navigate folders (Enter, q to quit)

💽 Step 3: Check Overall Disk Space with df

Section titled “💽 Step 3: Check Overall Disk Space with df”

Use the built-in df command to check how much disk space is left:

Terminal window
df -h ~

Sample Output:

Filesystem Size Used Avail Capacity Mounted on
/dev/disk3s1s1 500G 390G 110G 78% /

This tells you:

  • Total size of your disk
  • How much is used
  • How much is available

🧹 Step 4: Clean Common Large Directories

Section titled “🧹 Step 4: Clean Common Large Directories”

Used for build cache — safe to delete:

Terminal window
rm -rf ~/Library/Developer/Xcode/DerivedData/*

Stores archived .xcarchive files. Delete only if you no longer need them for distribution or symbolication:

Terminal window
rm -rf ~/Library/Developer/Xcode/Archives/*
Terminal window
rm -rf ~/.Trash/*
Terminal window
rm -rf ~/.npm/*
rm -rf ~/.cache/*

If you have multiple JavaScript projects (e.g., under hasdev/*), you can remove all node_modules like this:

Terminal window
find hasdev -type d -name node_modules -exec rm -rf {} +

Want a quick view of both disk usage and available space?

Terminal window
df -h ~
ncdu ~

ToolPurposeUsage Example
ncduAnalyze disk usage interactivelyncdu ~
dfView total and free disk spacedf -h ~
findSearch and clean large dirsfind . -name node_modules

Using ncdu + df gives you a powerful combo for managing disk usage without any bloated GUI tools. Clean regularly, and automate the tedious bits to keep your macOS development environment lean and fast.