Created
August 25, 2025 06:48
-
-
Save AmitGazal/0ae621c89d69146b31cb4ec1e33178c4 to your computer and use it in GitHub Desktop.
Bash script to free up disk space by cleaning Xcode’s DerivedData, Archives, Device Support, Simulators, and Documentation caches.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| echo "Cleaning up Xcode files…" | |
| # Show current heavy folders | |
| du -sh ~/Library/Developer/Xcode/DerivedData \ | |
| ~/Library/Developer/Xcode/Archives \ | |
| ~/Library/Developer/Xcode/iOS\ DeviceSupport \ | |
| ~/Library/Developer/CoreSimulator/Devices \ | |
| ~/Library/Developer/Xcode/DocumentationCache 2>/dev/null || true | |
| # 1) DerivedData | |
| if [ -d ~/Library/Developer/Xcode/DerivedData ]; then | |
| find ~/Library/Developer/Xcode/DerivedData -mindepth 1 -maxdepth 1 -exec rm -rf {} + 2>/dev/null || true | |
| echo "✓ Cleaned DerivedData" | |
| fi | |
| # 2) Archives | |
| if [ -d ~/Library/Developer/Xcode/Archives ]; then | |
| find ~/Library/Developer/Xcode/Archives -mindepth 1 -maxdepth 1 -exec rm -rf {} + 2>/dev/null || true | |
| echo "✓ Cleaned Archives" | |
| fi | |
| # 3) Device Support | |
| if [ -d ~/Library/Developer/Xcode/iOS\ DeviceSupport ]; then | |
| find ~/Library/Developer/Xcode/iOS\ DeviceSupport -mindepth 1 -maxdepth 1 -exec rm -rf {} + 2>/dev/null || true | |
| echo "✓ Cleaned iOS DeviceSupport" | |
| fi | |
| # 4) Simulators | |
| if [ -d ~/Library/Developer/CoreSimulator/Devices ]; then | |
| find ~/Library/Developer/CoreSimulator/Devices -mindepth 1 -maxdepth 1 -exec rm -rf {} + 2>/dev/null || true | |
| echo "✓ Cleaned Simulator Devices" | |
| fi | |
| # 5) Docs cache | |
| if [ -d ~/Library/Developer/Xcode/DocumentationCache ]; then | |
| find ~/Library/Developer/Xcode/DocumentationCache -mindepth 1 -maxdepth 1 -exec rm -rf {} + 2>/dev/null || true | |
| echo "✓ Cleaned Documentation Cache" | |
| fi | |
| # Show savings | |
| echo "" | |
| echo "Remaining sizes after cleanup:" | |
| du -sh ~/Library/Developer/Xcode/DerivedData \ | |
| ~/Library/Developer/Xcode/Archives \ | |
| ~/Library/Developer/Xcode/iOS\ DeviceSupport \ | |
| ~/Library/Developer/CoreSimulator/Devices \ | |
| ~/Library/Developer/Xcode/DocumentationCache 2>/dev/null || true | |
| echo "" | |
| echo "✨ Xcode cleanup complete!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment