108 lines
4.2 KiB
Bash
Executable File
108 lines
4.2 KiB
Bash
Executable File
#!/bin/bash
|
|
set -x # debug mode
|
|
|
|
# Create a temporary file to store the report
|
|
TEMP_FILE=$(mktemp)
|
|
|
|
# Write report header
|
|
echo "macOS Fast Disk Usage Analysis" >> "$TEMP_FILE"
|
|
echo "Generated on $(date)" >> "$TEMP_FILE"
|
|
echo "Finding where your 256GB is actually going..." >> "$TEMP_FILE"
|
|
echo "=============================================" >> "$TEMP_FILE"
|
|
echo >> "$TEMP_FILE"
|
|
|
|
# Overall disk usage
|
|
echo "OVERALL DISK USAGE:" >> "$TEMP_FILE"
|
|
df -h / >> "$TEMP_FILE"
|
|
echo >> "$TEMP_FILE"
|
|
|
|
# Quick size check of major directories (no sudo needed)
|
|
echo "MAJOR DIRECTORY SIZES (accessible without sudo):" >> "$TEMP_FILE"
|
|
echo "Applications: $(du -sh /Applications 2>/dev/null | cut -f1)" >> "$TEMP_FILE"
|
|
echo "Users: $(du -sh /Users 2>/dev/null | cut -f1)" >> "$TEMP_FILE"
|
|
echo "Your Home: $(du -sh "$HOME" 2>/dev/null | cut -f1)" >> "$TEMP_FILE"
|
|
echo >> "$TEMP_FILE"
|
|
|
|
# User directories breakdown
|
|
echo "YOUR HOME DIRECTORY BREAKDOWN:" >> "$TEMP_FILE"
|
|
du -sh "$HOME"/* 2>/dev/null | sort -hr >> "$TEMP_FILE"
|
|
echo >> "$TEMP_FILE"
|
|
|
|
# User Library breakdown (often huge)
|
|
echo "YOUR LIBRARY DIRECTORY - often contains huge files:" >> "$TEMP_FILE"
|
|
du -sh "$HOME/Library"/* 2>/dev/null | sort -hr | head -n 15 >> "$TEMP_FILE"
|
|
echo >> "$TEMP_FILE"
|
|
|
|
# Application sizes
|
|
echo "INSTALLED APPLICATIONS - largest first:" >> "$TEMP_FILE"
|
|
du -sh /Applications/* 2>/dev/null | sort -hr | head -n 15 >> "$TEMP_FILE"
|
|
echo >> "$TEMP_FILE"
|
|
|
|
# Time Machine local snapshots (major space hog)
|
|
echo "TIME MACHINE LOCAL SNAPSHOTS - can be huge:" >> "$TEMP_FILE"
|
|
snapshots=$(tmutil listlocalsnapshots / 2>/dev/null | wc -l | tr -d ' ')
|
|
echo "Number of local snapshots: $snapshots" >> "$TEMP_FILE"
|
|
if [ "$snapshots" -gt 0 ]; then
|
|
echo "Recent snapshots:" >> "$TEMP_FILE"
|
|
tmutil listlocalsnapshots / 2>/dev/null | head -n 5 >> "$TEMP_FILE"
|
|
fi
|
|
echo >> "$TEMP_FILE"
|
|
|
|
# Large files in user area
|
|
echo "LARGEST FILES IN YOUR HOME - over 500MB:" >> "$TEMP_FILE"
|
|
find "$HOME" -type f -size +500M 2>/dev/null | head -n 10 | xargs ls -lh 2>/dev/null | awk '{print $5 "\t" $9}' >> "$TEMP_FILE"
|
|
echo >> "$TEMP_FILE"
|
|
|
|
# Common space hogs
|
|
echo "COMMON SPACE HOGS:" >> "$TEMP_FILE"
|
|
echo "Downloads folder: $(du -sh "$HOME/Downloads" 2>/dev/null | cut -f1)" >> "$TEMP_FILE"
|
|
echo "Desktop: $(du -sh "$HOME/Desktop" 2>/dev/null | cut -f1)" >> "$TEMP_FILE"
|
|
echo "Documents: $(du -sh "$HOME/Documents" 2>/dev/null | cut -f1)" >> "$TEMP_FILE"
|
|
echo "Movies: $(du -sh "$HOME/Movies" 2>/dev/null | cut -f1)" >> "$TEMP_FILE"
|
|
echo "Pictures: $(du -sh "$HOME/Pictures" 2>/dev/null | cut -f1)" >> "$TEMP_FILE"
|
|
echo "Music: $(du -sh "$HOME/Music" 2>/dev/null | cut -f1)" >> "$TEMP_FILE"
|
|
echo >> "$TEMP_FILE"
|
|
|
|
# Development files that can be safely removed
|
|
echo "DEVELOPMENT FILES - safe to remove, will rebuild:" >> "$TEMP_FILE"
|
|
echo "node_modules directories:" >> "$TEMP_FILE"
|
|
find "$HOME" -name "node_modules" -type d 2>/dev/null | xargs du -sh 2>/dev/null | sort -hr | head -n 10 >> "$TEMP_FILE"
|
|
echo >> "$TEMP_FILE"
|
|
|
|
# Xcode files
|
|
echo "XCODE FILES - safe to delete, will regenerate:" >> "$TEMP_FILE"
|
|
if [ -d "$HOME/Library/Developer/Xcode/DerivedData" ]; then
|
|
echo "Xcode DerivedData: $(du -sh "$HOME/Library/Developer/Xcode/DerivedData" | cut -f1)" >> "$TEMP_FILE"
|
|
fi
|
|
if [ -d "$HOME/Library/Developer/CoreSimulator" ]; then
|
|
echo "iOS Simulators: $(du -sh "$HOME/Library/Developer/CoreSimulator" | cut -f1)" >> "$TEMP_FILE"
|
|
fi
|
|
echo >> "$TEMP_FILE"
|
|
|
|
# Caches
|
|
echo "CACHE DIRECTORIES - safe to clear:" >> "$TEMP_FILE"
|
|
du -sh "$HOME/Library/Caches"/* 2>/dev/null | sort -hr | head -n 10 >> "$TEMP_FILE"
|
|
echo >> "$TEMP_FILE"
|
|
|
|
# System info
|
|
echo "SYSTEM SPACE ESTIMATE:" >> "$TEMP_FILE"
|
|
echo "To get exact system usage, run: sudo du -sh /System /Library /private 2>/dev/null" >> "$TEMP_FILE"
|
|
echo >> "$TEMP_FILE"
|
|
|
|
# Post the report to Hastebin
|
|
RESPONSE=$(curl -s -X POST -d "$(cat "$TEMP_FILE")" "https://haste.nixc.us/documents")
|
|
|
|
# Extract the key from the Hastebin response
|
|
KEY=$(echo "$RESPONSE" | grep -o '"key":"[^"]*"' | cut -d'"' -f4)
|
|
|
|
if [ -n "$KEY" ]; then
|
|
echo "Fast disk usage report uploaded to Hastebin!"
|
|
echo "See where your 256GB is going: https://haste.nixc.us/$KEY"
|
|
else
|
|
echo "Error: Failed to upload report to Hastebin."
|
|
echo "Local disk usage report:"
|
|
cat "$TEMP_FILE"
|
|
fi
|
|
|
|
# Clean up the temporary file
|
|
rm -f "$TEMP_FILE" |