Skip to content

Instantly share code, notes, and snippets.

@ssoper
Created November 13, 2020 19:23
Show Gist options
  • Save ssoper/1852c36d17ce48dc504475d0b583778d to your computer and use it in GitHub Desktop.
Save ssoper/1852c36d17ce48dc504475d0b583778d to your computer and use it in GitHub Desktop.
My homegrown attempt to figure out what’s going on when OSX claims “Other” is taking up half my HDD
#!/usr/bin/env bash
# Root folder
echo "Largest folders at /"
du -hs /* 2>&1 | grep -v 'permitted' | sort -hr | grep '^\s\?\d\+\(\.\d\+\)\?G'
# /private/var temp
echo "Largest temporary folders"
du -hs $TMPDIR../C/* 2>&1 | grep -v 'permitted' | sort -hr | grep '^\s\?\d\+\(\.\d\+\)\?G'
# ~
echo "Largest user folders"
du -hs ~/* 2>&1 | grep -v 'permitted' | sort -hr | grep '^\s\?\d\+\(\.\d\+\)\?G'
# All files
echo "Largest files"
find / -size +1GB 2>&1 | grep -v 'permitted' | grep -v 'Permission' | grep -v 'No such file' | xargs du -sh 2>/dev/null | sort -hr
# Xcode
# inspired by https://gist.github.com/maciekish/66b6deaa7bc979d0a16c50784e16d697
echo "Cleaning Xcode caches"
echo "Before $(du -sh ~/Library/Developer)"
killall Xcode 2>/dev/null
xcrun -k
xcrun simctl delete unavailable
xcodebuild -alltargets clean 1>2 2>/dev/null
rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache"
rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang.$(whoami)/ModuleCache"
rm -rf ~/Library/Developer/Xcode/DerivedData/*
rm -rf ~/Library/Caches/com.apple.dt.Xcode/*
echo "After $(du -sh ~/Library/Developer)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment