#!/bin/bash # Aggressive Free System Data (351GB) # When normal methods don't work set -e echo "=== Aggressive Free System Data (351GB) ===" echo "" echo "Since normal methods didn't work, we need to be more aggressive." echo "" FREE_SPACE_BEFORE=$(df / | tail -1 | awk '{print $4}') FREE_SPACE_GB_BEFORE=$(echo "scale=2; $FREE_SPACE_BEFORE / 1024 / 1024" | bc) echo "Current free space: ${FREE_SPACE_GB_BEFORE}GB" echo "" echo "🔍 Checking Time Machine configuration..." TM_DEST=$(defaults read /Library/Preferences/com.apple.TimeMachine LastDestinationID 2>/dev/null || echo "NONE") if [ "$TM_DEST" != "NONE" ]; then echo " ⚠️ Time Machine destination still configured: $TM_DEST" echo " This means snapshots may still be created!" echo "" echo " You MUST remove it in System Settings:" echo " System Settings → Time Machine → Remove backup disk" echo "" read -p " Have you removed it? (y/n) " -n 1 -r echo "" if [[ ! $REPLY =~ ^[Yy]$ ]]; then echo " ⚠️ Please remove it first!" exit 1 fi else echo " ✅ Time Machine destination removed" fi echo "" echo "🔧 Method 1: Force delete all local snapshots..." SNAPSHOTS=$(tmutil listlocalsnapshots / 2>/dev/null | grep -v "Snapshots for disk" | grep -v "^$") if [ -n "$SNAPSHOTS" ]; then echo "$SNAPSHOTS" | while read snapshot; do if [ -n "$snapshot" ]; then SNAP_DATE=$(echo "$snapshot" | sed 's/.*\.\([0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}-[0-9]\{6\}\)\.backup/\1/') if [ -n "$SNAP_DATE" ]; then echo " Deleting: $snapshot" sudo tmutil deletelocalsnapshots "$SNAP_DATE" 2>&1 || echo " ⚠️ Failed (ghost entry)" fi fi done else echo " No snapshots found" fi echo "" echo "🔧 Method 2: Aggressive thinning (keep only 1GB, 1 day)..." sudo tmutil thinlocalsnapshots / 1000000000 1 2>&1 echo " ✓ Completed" echo "" echo "🔧 Method 3: Disable Time Machine completely..." sudo tmutil disable 2>/dev/null || echo " ⚠️ Could not disable (may already be disabled)" echo "" echo "🔧 Method 4: Clear Time Machine database..." echo " ⚠️ This will clear Time Machine's local database" read -p " Proceed? (y/n) " -n 1 -r echo "" if [[ $REPLY =~ ^[Yy]$ ]]; then # Backup first sudo cp -r /Library/Preferences/com.apple.TimeMachine.plist /Library/Preferences/com.apple.TimeMachine.plist.backup 2>/dev/null || true echo " Backed up preferences" # Clear local snapshots database sudo rm -rf /System/Volumes/Data/.timemachine/* 2>/dev/null || true echo " ✓ Cleared Time Machine local data" fi echo "" echo "🔧 Method 5: Force filesystem sync and purge..." sync if command -v purge &> /dev/null; then sudo purge echo " ✓ Purged" fi echo "" echo "🔧 Method 6: Use macOS storage optimization..." echo "" echo " ⚠️ CRITICAL: You need to use macOS's built-in tool:" echo "" echo " 1. Apple Menu → About This Mac → Storage" echo " 2. Click 'Manage...'" echo " 3. Look for 'Optimize Storage' or similar option" echo " 4. This will release purgeable space" echo "" echo " OR use Terminal:" echo " sudo tmutil thinlocalsnapshots / 1000000000 1" echo " sudo purge" echo "" echo "⏳ Waiting for system to update..." sleep 15 # Check results FREE_SPACE_AFTER=$(df / | tail -1 | awk '{print $4}') FREE_SPACE_GB_AFTER=$(echo "scale=2; $FREE_SPACE_AFTER / 1024 / 1024" | bc) FREED_GB=$(echo "scale=2; $FREE_SPACE_GB_AFTER - $FREE_SPACE_GB_BEFORE" | bc) echo "" echo "=== Results ===" echo " Before: ${FREE_SPACE_GB_BEFORE}GB free" echo " After: ${FREE_SPACE_GB_AFTER}GB free" if (( $(echo "$FREED_GB > 100" | bc -l) )); then echo " ✅ Successfully freed: ${FREED_GB}GB!" elif (( $(echo "$FREED_GB > 0" | bc -l) )); then echo " ✅ Freed: ${FREED_GB}GB" else echo " ⚠️ No space freed yet" fi echo "" echo "=== If Still No Change ===" echo "" echo "The 351GB in System Data is likely:" echo " 1. Purgeable space that macOS won't release until needed" echo " 2. APFS snapshot overhead (the OS update snapshot)" echo " 3. Reserved space for system operations" echo "" echo "Try these:" echo "" echo "1. **Create a large file to force purge**:" echo " This forces macOS to release purgeable space:" echo " dd if=/dev/zero of=~/test_large_file bs=1g count=50" echo " (This creates a 50GB file, forcing purge)" echo " Then delete it: rm ~/test_large_file" echo "" echo "2. **Use Activity Monitor**:" echo " Open Activity Monitor → Disk tab" echo " Look for 'Purgeable' space" echo "" echo "3. **Check Storage Management again**:" echo " The System Data may show as 'Purgeable'" echo " macOS will release it when space is actually needed" echo "" echo "4. **The space may already be available**:" echo " Even though System Data shows 351GB, the space" echo " may be purgeable and available when needed" echo ""