Skip to content

Instantly share code, notes, and snippets.

@bquast
Last active May 12, 2026 18:51
Show Gist options
  • Select an option

  • Save bquast/54ac1356018a569fe495aaa3403d7824 to your computer and use it in GitHub Desktop.

Select an option

Save bquast/54ac1356018a569fe495aaa3403d7824 to your computer and use it in GitHub Desktop.
Saving disk space: below script lists the large files and folders, to be copy-pasted into an LLM, for space-saving suggestions
#!/bin/zsh
# cleanup.sh
# Usage: ./cleanup.sh [directory]
# Default to HOME if no directory is provided
TARGET="${1:-$HOME}"
echo "### macOS SSD Analysis for: $TARGET"
echo "### Date: $(date)"
echo "---"
echo "#### 1. Top 50 Largest Directories (Depth 2)"
# du: -g (GB), -x (one FS), -d 2 (depth)
du -gx -d 2 "$TARGET" 2>/dev/null | \
sort -rn | \
awk '
BEGIN { print "| Size (GB) | Path |"; print "|-----------|------|" }
$1 > 0 { printf "| %-9s | %s |\n", $1, $2 }
' | head -n 50
echo ""
echo "#### 2. Extra Large Files (>500MB) via Spotlight"
# mdfind: queries the metadata index instantly
# stat: gets the raw file size in bytes
# awk: converts to MB and formats the table
mdfind -onlyin "$TARGET" "kMDItemFSSize > 500000000" 2>/dev/null | \
while read -r file; do
stat -f "%z %N" "$file" 2>/dev/null
done | sort -rn | head -n 50 | \
awk '
BEGIN { print "| Size (MB) | Path |"; print "|-----------|------|" }
{
size_mb = $1 / 1048576
$1 = ""
sub(/^ /, "", $0)
printf "| %-9.0f | %s |\n", size_mb, $0
}
'
echo ""
echo "#### 3. Package Manager Caches (Brew & MacPorts)"
awk 'BEGIN { print "| Manager | Size (GB) | Path |"; print "|---------|-----------|------|" }'
# Homebrew
if command -v brew >/dev/null 2>&1; then
BREW_CACHE=$(brew --cache)
BREW_SIZE=$(du -gx -d 0 "$BREW_CACHE" 2>/dev/null | cut -f1)
printf "| Homebrew | %-9s | %s |\n" "${BREW_SIZE:-0}" "$BREW_CACHE"
fi
# MacPorts (typically stores distfiles and logs here)
MACPORTS_DIR="/opt/local/var/macports"
if [ -d "$MACPORTS_DIR" ]; then
PORT_SIZE=$(du -gx -d 0 "$MACPORTS_DIR" 2>/dev/null | cut -f1)
printf "| MacPorts | %-9s | %s |\n" "${PORT_SIZE:-0}" "$MACPORTS_DIR"
fi
@bquast

bquast commented May 12, 2026

Copy link
Copy Markdown
Author

Download the file.

Make the file executable:

chmod +x ./big-files-list.sh

Execute the file:

./big-files-list.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment