Skip to content

Instantly share code, notes, and snippets.

@richy486
Last active November 22, 2019 18:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richy486/1a8f184ca0c3f8c47ea06023865d19ef to your computer and use it in GitHub Desktop.
Save richy486/1a8f184ca0c3f8c47ea06023865d19ef to your computer and use it in GitHub Desktop.
Xcode clean up
#!/bin/bash
# Clean Xcode files
# @richy486 https://gist.github.com/richy486
# http://ajithrnayak.com/post/95441624221/xcode-users-can-free-up-space-on-your-mac
STATUS='\033[0;36m'
WARNING='\033[0;33m'
ERROR='\033[0;31m'
CMD='\033[0;92m'
NC='\033[0m' # No Color
OLDER_THAN=365
echo -e "\n${STATUS}Deleting derived data${NC}"
rm -rf ~/Library/Developer/Xcode/DerivedData
echo -e "\n${STATUS}Deleting old caches directory${NC}"
rm -rf ~/Library/Caches/com.apple.dt.Xcode
echo -e "\n${STATUS}Deleting unavailable simulators${NC}"
xcrun simctl delete unavailable
echo -e "\n${STATUS}Deleting archives older than ${OLDER_THAN} days${NC}"
# Using find
find ~/Library/Developer/Xcode/Archives * -mtime +${OLDER_THAN} -exec rm -rf "{}" \;
# Using date of folder as macOS/Xcode changes the modified date
# https://unix.stackexchange.com/a/516358/383242
discriminant=$(date -v -1y "+%Y-%m-%d")
pushd ~/Library/Developer/Xcode/Archives;
list=()
shopt -s nullglob
for file in *; do
if [[ $file < $discriminant ]]; then
rm -rf $file
fi
done
popd;
echo -e "\n${STATUS}Deleting device support files older than ${OLDER_THAN} days${NC}"
find ~/Library/Developer/Xcode/iOS\ DeviceSupport * -mtime +${OLDER_THAN} -exec rm -rf "{}" \;
echo -e "\n${STATUS}Deleting simulator files older than ${OLDER_THAN} days${NC}"
find ~/Library/Developer/CoreSimulator * -mtime +${OLDER_THAN} -exec rm -rf "{}" \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment