Skip to content

Instantly share code, notes, and snippets.

@arrrrny
Last active October 19, 2024 06:52
Show Gist options
  • Save arrrrny/a946cbbc039a0cce8848bc1130bfbda2 to your computer and use it in GitHub Desktop.
Save arrrrny/a946cbbc039a0cce8848bc1130bfbda2 to your computer and use it in GitHub Desktop.
Mac Apple Silicon Clean Up Space
#!/bin/bash
# --- Xcode Cleanup ---
# Clear Derived Data
rm -rf ~/Library/Developer/Xcode/DerivedData/*
# Clear Xcode Caches
rm -rf ~/Library/Caches/com.apple.dt.Xcode/*
# Clear Device Support Files
rm -rf ~/Library/Developer/Xcode/iOS\ DeviceSupport/*
# Clear Archives
rm -rf ~/Library/Developer/Xcode/Archives/*
# Clear Documentation Cache
rm -rf ~/Library/Developer/Shared/Documentation/DocSets/*
# Optional: Clear Simulator Data
rm -rf ~/Library/Developer/CoreSimulator/Caches/*
rm -rf ~/Library/Developer/CoreSimulator/Devices/*
# Remove unused Xcode Simulator Runtimes
xcrun simctl delete unavailable
# Clear Xcode Provisioning Profiles
rm -rf ~/Library/MobileDevice/Provisioning\ Profiles/*
# --- Android Studio Cleanup ---
# Clear Android Studio Caches
rm -rf ~/.AndroidStudio*/system/caches/*
rm -rf ~/.AndroidStudio*/system/index/*
# Clear Gradle Caches
rm -rf ~/.gradle/caches/
# Clear Android SDK Cache
rm -rf ~/Library/Android/sdk/.cache/*
# Remove unused SDK platforms and system images (customize as needed)
# Example: Remove Android API 29
# rm -rf ~/Library/Android/sdk/platforms/android-29
# rm -rf ~/Library/Android/sdk/system-images/android-29
# Remove build directories in Android projects
# find ~/Projects -type d -name "build" -prune -exec rm -rf {} +
# --- Flutter Cleanup ---
# Recursively remove all 'build' directories in Flutter projects
find ~/Developer -type d -name "build" -prune -exec rm -rf {} +
# Clean Flutter's pub cache
flutter pub cache clean
# Navigate to Flutter SDK directory and remove Flutter's cache
FLUTTER_SDK_PATH=$(which flutter | sed "s:bin/flutter::")
rm -rf "$FLUTTER_SDK_PATH/bin/cache/"
# Recursively remove '.dart_tool' directories
find ~/Developer -type d -name ".dart_tool" -prune -exec rm -rf {} +
# --- General Cleanup ---
# Remove System and User Cache Files
sudo rm -rf ~/Library/Caches/* /Library/Caches/*
# Clear Homebrew caches and cleanup
brew cleanup -s
brew cleanup
# Remove Docker images, containers, and volumes
docker system prune -a --volumes -f
# Clear Safari cache
rm -rf ~/Library/Caches/com.apple.Safari/*
# Clear Google Chrome cache
rm -rf ~/Library/Caches/Google/Chrome/*
# Clear Firefox cache
rm -rf ~/Library/Caches/Firefox/Profiles/*.default-release/cache2/*
# Remove old iOS device backups (customize as needed)
# Example: Uncomment and replace <backup_folder> with actual folder name
# rm -rf ~/Library/Application\ Support/MobileSync/Backup/<backup_folder>
# Remove specific large files (customize as needed)
# Example: Uncomment and replace with actual file path
# rm -f ~/Downloads/largefile.zip
# Remove specific applications (customize as needed)
# Example: Uncomment to remove QuickTime Player
# sudo rm -rf /Applications/QuickTime\ Player.app
# Empty Trash
rm -rf ~/.Trash/*
echo "Cleanup completed successfully."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment