Skip to content

Instantly share code, notes, and snippets.

@nanotaboada
Created May 8, 2025 13:24
Show Gist options
  • Save nanotaboada/526c74dab1b1bb0a2b122ea9d23a3025 to your computer and use it in GitHub Desktop.
Save nanotaboada/526c74dab1b1bb0a2b122ea9d23a3025 to your computer and use it in GitHub Desktop.
🧽 Selective cleaner for ~/Library/Caches/
#!/bin/bash
# ------------------------------------------------------------------------------
# 🧽 Selective cleaner for ~/Library/Caches/
#
# This script scans your user cache folder (~Library/Caches) and interactively
# offers to delete only medium or large-sized app cache folders.
#
# Features:
# - Skips small cache folders (<10MB)
# - Shows size and folder name
# - Asks confirmation before deletion
# - Avoids touching system or protected directories
#
# Usage:
# ./clean-user-caches.sh
# ------------------------------------------------------------------------------
# Color output
GREEN="\033[0;32m"
RED="\033[0;31m"
YELLOW="\033[1;33m"
BLUE="\033[0;34m"
NC="\033[0m"
CACHE_DIR="$HOME/Library/Caches"
MIN_SIZE_MB=10 # Only show folders >= this size
echo -e "${BLUE}🔍 Scanning user cache directory: ${CACHE_DIR}${NC}"
echo ""
# Find each folder manually
IFS=$'\n'
for folder in $(find "$CACHE_DIR" -mindepth 1 -maxdepth 1 -type d); do
# Ignore unreadable folders
if ! du_output=$(du -sk "$folder" 2>/dev/null); then
continue
fi
size_kb=$(echo "$du_output" | awk '{print $1}')
size_mb=$((size_kb / 1024))
folder_name=$(basename "$folder")
if [ "$size_mb" -ge "$MIN_SIZE_MB" ]; then
echo -e "📦 ${YELLOW}${folder_name}${NC} - ${size_mb} MB"
printf "🗑️ Delete this cache folder? [y/N]: "
read confirm
if [[ "$confirm" =~ ^[Yy]$ ]]; then
rm -rf "$folder"
echo -e "${GREEN}✅ Deleted: ${folder_name}${NC}"
else
echo -e "${BLUE}➡️ Skipped: ${folder_name}${NC}"
fi
echo ""
fi
done
unset IFS
echo -e "${BLUE}🎉 Done cleaning caches!${NC} 🧼"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment