#!/bin/bash # Quick Fix: Free up space for Time Machine # This script performs safe cleanup operations to free disk space set -e echo "=== Time Machine Disk Space Fix ===" echo "" echo "This script will help free up space so Time Machine can work." echo "" # Check current free space FREE_SPACE=$(df / | tail -1 | awk '{print $4}') FREE_SPACE_GB=$(echo "scale=2; $FREE_SPACE / 1024 / 1024" | bc) echo "Current free space: ${FREE_SPACE_GB}GB" echo "" # Ask for confirmation read -p "Do you want to proceed with safe cleanup? (y/n) " -n 1 -r echo "" if [[ ! $REPLY =~ ^[Yy]$ ]]; then echo "Cancelled." exit 0 fi echo "" echo "๐Ÿงน Cleaning up..." # 1. Empty Trash if [ -d ~/.Trash ] && [ "$(ls -A ~/.Trash 2>/dev/null)" ]; then TRASH_SIZE=$(du -sh ~/.Trash 2>/dev/null | awk '{print $1}') echo " Emptying Trash ($TRASH_SIZE)..." rm -rf ~/.Trash/* ~/.Trash/.* 2>/dev/null || true echo " โœ“ Trash emptied" else echo " โœ“ Trash already empty" fi # 2. Clean Library Caches (safe - will regenerate) if [ -d ~/Library/Caches ]; then CACHES_SIZE=$(du -sh ~/Library/Caches 2>/dev/null | awk '{print $1}') echo " Cleaning Library/Caches ($CACHES_SIZE)..." # Keep some important caches mkdir -p ~/Library/Caches/backup_temp find ~/Library/Caches -mindepth 1 -maxdepth 1 ! -name "backup_temp" -exec mv {} ~/Library/Caches/backup_temp/ \; 2>/dev/null || true rm -rf ~/Library/Caches/backup_temp/* 2>/dev/null || true rmdir ~/Library/Caches/backup_temp 2>/dev/null || true echo " โœ“ Caches cleaned" fi # 3. Clean user cache if [ -d ~/.cache ]; then CACHE_SIZE=$(du -sh ~/.cache 2>/dev/null | awk '{print $1}') echo " Cleaning ~/.cache ($CACHE_SIZE)..." rm -rf ~/.cache/* 2>/dev/null || true echo " โœ“ User cache cleaned" fi # 4. Clean npm cache (if exists) if command -v npm &> /dev/null; then NPM_CACHE_SIZE=$(du -sh ~/.npm 2>/dev/null | awk '{print $1}' || echo "0") if [ "$NPM_CACHE_SIZE" != "0" ] && [ -d ~/.npm ]; then echo " Cleaning npm cache ($NPM_CACHE_SIZE)..." npm cache clean --force 2>/dev/null || true echo " โœ“ npm cache cleaned" fi fi echo "" echo "๐Ÿ“Š Checking new disk space..." NEW_FREE_SPACE=$(df / | tail -1 | awk '{print $4}') NEW_FREE_SPACE_GB=$(echo "scale=2; $NEW_FREE_SPACE / 1024 / 1024" | bc) FREED_GB=$(echo "scale=2; $NEW_FREE_SPACE_GB - $FREE_SPACE_GB" | bc) echo "" echo "=== Results ===" echo " Before: ${FREE_SPACE_GB}GB free" echo " After: ${NEW_FREE_SPACE_GB}GB free" if (( $(echo "$FREED_GB > 0" | bc -l) )); then echo " Freed: ${FREED_GB}GB" fi echo "" # Check if we have enough space now if (( $(echo "$NEW_FREE_SPACE_GB < 5" | bc -l) )); then echo "โš ๏ธ Still low on space. Additional recommendations:" echo "" echo " 1. Review Downloads folder (19GB found):" echo " cd ~/Downloads && ls -lhS | head -20" echo "" echo " 2. Check Documents folder (60GB found):" echo " Move large files to NAS if possible" echo "" echo " 3. Review .ollama folder (17GB found):" echo " Consider removing unused models" echo "" echo " 4. Use macOS Storage Management:" echo " Apple Menu โ†’ About This Mac โ†’ Storage โ†’ Manage" echo "" else echo "โœ… Good! You should have enough space for Time Machine now." echo " Try running Time Machine backup again." fi echo ""