diff --git a/README.md b/README.md index aaa2374..5b5c6ae 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,106 @@ # Disk Space Report Script -This script helps diagnose disk usage by estimating potential storage savings and identifying large directories on your system. It does not take any action; it only reports the current state of your disk usage. +A comprehensive disk space analysis tool for Ubuntu/Linux systems that helps identify storage usage patterns and suggests cleanup opportunities. ## Features -- Estimates the size of the apt cache. -- Estimates the size of old installed packages. -- Estimates the size of journal logs. -- Estimates the size of temporary files. -- Estimates the size of unused Docker volumes. -- Lists directories consuming more than 5GB and 10GB. +- **APT Cache Analysis**: Estimates size of package cache that can be cleared +- **Package Management**: Identifies old installed packages taking up space +- **Journal Log Analysis**: Checks system journal logs for cleanup opportunities +- **Temporary Files Check**: Analyzes temporary directories for cleanup +- **Docker Volume Analysis**: Identifies unused Docker volumes consuming space +- **Docker Log Management**: Finds large Docker log files and suggests rotation +- **Large Directory Discovery**: Lists directories consuming significant space +- **Automatic Report Upload**: Uploads results to Hastebin for easy sharing + +## Requirements + +- Ubuntu/Linux system +- `sudo` privileges for comprehensive analysis +- `docker` (optional, for Docker-related analysis) +- `jq` for JSON parsing (for Hastebin upload) +- `curl` for report uploading + +## Installation + +```bash +# Clone the repository +git clone https://github.com/yourusername/disk-space-report.git +cd disk-space-report + +# Make the script executable +chmod +x disk-check.sh +``` ## Usage -To use this script, execute it directly from the URL without downloading it, which is particularly useful when disk space is limited. - -### Execute Directly from URL - -Run the script directly from the URL using `curl` and piping to `bash`: - ```bash -curl -sSL https://git.nixc.us/colin/disk-space-report/raw/branch/main/disk-check.sh | bash +./disk-check.sh ``` -## Output +The script will: +1. Analyze various system components for space usage +2. Generate a comprehensive report +3. Save the report to `/tmp/disk_space_report.log` +4. Upload the report to Hastebin and provide a shareable URL -The script will output the following information: +## What It Analyzes -- The size of the apt cache. -- The size of old installed packages. -- The size of journal logs. -- The size of temporary files. -- The size of unused Docker volumes. -- Directories consuming more than 5GB and 10GB. +### System Components +- **APT Cache** (`/var/cache/apt`): Downloaded package files +- **Package Lists** (`/var/lib/apt/lists`): Package index files +- **Journal Logs**: System logging data +- **Temporary Files** (`/tmp`, `/var/tmp`): Temporary system files -## Note +### Docker Components (if Docker is installed) +- **Unused Volumes**: Dangling Docker volumes +- **Large Log Files**: Docker container logs over 1GB -This script requires `sudo` privileges to estimate certain sizes and access system directories. \ No newline at end of file +### Directory Analysis +- **Large Directories**: Directories consuming more than 5GB and 10GB +- **Home Directory Analysis**: Large directories in user home folders + +## Sample Output + +The script provides estimates like: +``` +Estimating the size of the apt cache: +1.2G /var/cache/apt + +Estimating the size of journal logs: +Archived and active journals take up 2.1G in the file system. + +Directories in / consuming more than 5GB: +7.2G /var/lib/docker +12G /usr/share +``` + +## Cleanup Suggestions + +Based on the analysis, you can: + +1. **Clear APT cache**: `sudo apt clean` +2. **Remove old packages**: `sudo apt autoremove` +3. **Clean journal logs**: `sudo journalctl --vacuum-time=30d` +4. **Clear temporary files**: `sudo rm -rf /tmp/*` (use with caution) +5. **Remove unused Docker volumes**: `docker volume prune` +6. **Truncate Docker logs**: Use the provided command in the script output + +## macOS Version + +For macOS users, there's also a `disk-check-macos.sh` version that provides similar functionality adapted for macOS systems. + +## Safety Notes + +- This script only **analyzes** disk usage - it doesn't delete anything +- Always review suggested cleanup commands before running them +- Some cleanup operations cannot be undone +- The script requires `sudo` for comprehensive system analysis + +## Contributing + +Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests. + +## License + +This project is licensed under the MIT License. \ No newline at end of file diff --git a/disk-check-macos.sh b/disk-check-macos.sh new file mode 100755 index 0000000..96c51ef --- /dev/null +++ b/disk-check-macos.sh @@ -0,0 +1,108 @@ +#!/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" \ No newline at end of file