Files

2.9 KiB

name, description
name description
macos-disk-cleanup Use when a Mac disk is full. Find hogs, clean, verify freed.

macOS Disk Cleanup

Procedure

  1. Diagnose the real picture first.

    • df -h / for headline capacity, but also diskutil apfs list | grep -E "Capacity|Size" — on an APFS container with multiple volumes (system, data, VM, Preboot) the root / numbers can mislead; /System/Volumes/Data usually holds the user data and is the one that's actually full.
    • Rank hogs top-down, not file-by-file: du -sh ~/* | sort -rh, then drill into the biggest hits (~/Library/*, /Applications/*.app, /Library/Developer/*). Don't du the whole tree at once — rank one level, descend only into the big entries.
    • Treat any /private/var/folders/.../Nextcloud.app/Wrapper or similar sandbox mount showing huge usage as a view of the SAME underlying volume, not a separate cost — don't double-count it.
  2. After deleting anything, the freed space often does NOT show up in df immediately. Check for local Time Machine snapshots holding the deleted blocks:

    • tmutil listlocalsnapshots /
    • tmutil deletelocalsnapshots <snapshot-date-id> for each com.apple.TimeMachine.* entry (leave com.apple.os.update-* ones alone, those are OS-update snapshots).
    • Re-run df -h / after — this step alone can be the difference between "nothing was freed" and the real number. Always check this before telling the user a deletion didn't help.
  3. Xcode iOS Simulator bloat (/Library/Developer/CoreSimulator, often tens to 100+ GB) is safe to clear without touching Xcode.app itself:

    • xcrun simctl delete all (removes simulator device instances)
    • xcrun simctl runtime delete all (removes the downloaded iOS runtime disk images — this is where most of the space actually is, in CoreSimulator/Volumes and /Cryptex)
    • Verify with du -sh /Library/Developer/CoreSimulator before/after.
  4. Files refusing to delete with "Operation not permitted" despite correct ownership are usually flagged immutable (uchg), common in old synced/backup folders:

    • Check: ls -lO <file> (flags column shows uchg).
    • Fix: chflags -R nouchg,nouappnd,noschg,nosappnd <dir> then retry rm -rf.
  5. Deduplicating against a reference/cloud copy: match candidates by (filename, exact byte size), not filename alone. Files with the same name but a different size are a different export/version — do not delete those without explicit confirmation, even if the user said "duplicates can go". Report the ambiguous set back instead of guessing.

  6. Before pronouncing something "long unused" for cleanup (e.g. local LLM models, caches), check stat -f "%a %m" <file> for actual access/modify time — don't assume age from directory listing alone. If there's only one item in the category asked about, there's nothing to "sort out"; say so rather than inventing a selection.