All tools

Mac cleanup commands

Pick the caches you want gone — node_modules, DerivedData, Gradle, Homebrew, Docker — and get two commands: one that measures what each is costing you, one that deletes it. Everything on the list regenerates itself; the things that don't are listed separately, with the reason.

Written for developers who already know what these paths are. Almost nothing on the list is destructive — the cost of deleting it is a rebuild or a re-download — but the commands run as you, with no confirmation and no undo. Read the script before you paste it, and use it at your own risk.

4 of 21 selected

Project folders

Dependencies and build output living inside your repositories. The single biggest win on most machines, and all of it comes back with one install or build.

Package manager caches

Downloaded archives kept so the next install is fast. Clearing them makes exactly one install slow.

Xcode and simulators

The quietest disk hog on a Mac used for iOS work. DerivedData alone routinely passes 50 GB.

Android and Gradle

Everything here re-downloads or rebuilds. The one rule is stopping the daemons before the delete, not after.

Containers and the rest

Two more places that grow without anyone noticing.

Your script

Run the first block, decide whether the space is worth it, then run the second. Nothing here runs on this page — it only writes the commands out.

Searched recursively. Resolves to $HOME/code.

See what it is costing you
bash
ROOT="$HOME/code"

# node_modules
find "$ROOT" -type d -name node_modules -prune -exec du -sh {} + | sort -rh | head -20

# Next.js build output
find "$ROOT" -type d -name .next -prune -exec du -sh {} + | sort -rh | head -20

# npm
du -sh "$HOME/.npm" 2>/dev/null

# DerivedData
du -sh "$HOME/Library/Developer/Xcode/DerivedData" 2>/dev/null
Delete it
bash
ROOT="$HOME/code"

# node_modules
find "$ROOT" -type d -name node_modules -prune -exec rm -rf {} +

# Next.js build output
find "$ROOT" -type d -name .next -prune -exec rm -rf {} +

# npm
npm cache clean --force

# DerivedData
rm -rf "$HOME/Library/Developer/Xcode/DerivedData"
Before you run it
  • DerivedData: Quit Xcode first — it re-indexes on the next launch either way.

Left out on purpose

These are the neighbours of everything above, and they look just as disposable. They are not — each one holds something you cannot regenerate, so prune them by hand.

  • Xcode archives~/Library/Developer/Xcode/Archives carries the dSYMs for builds you have already shipped. Delete one and the crash reports from that release stop symbolicating.
  • Android emulators~/.android/avd is the emulators themselves and their disk state. Deleting one wipes everything installed inside it.
  • SDK system images and the NDKLarge, but a slow re-download and easy to remove selectively in the Android Studio SDK Manager instead.
  • Docker volumesdocker system prune above deliberately omits --volumes. Adding that flag is how you delete a local database.
  • dist and build foldersA sweep by name is tempting, but plenty of repositories commit a dist. Only the Gradle entry above matches build directories, and only next to a build.gradle.