Skip to content

Instantly share code, notes, and snippets.

@Keithsel
Last active February 3, 2026 06:58
Show Gist options
  • Select an option

  • Save Keithsel/317bc9168a7673aeb70086678f7fe87f to your computer and use it in GitHub Desktop.

Select an option

Save Keithsel/317bc9168a7673aeb70086678f7fe87f to your computer and use it in GitHub Desktop.
Clean up pacman and paru cache (yay should work the same, change the name of the aur wrapper)
#!/bin/bash
set -euo pipefail
# Better safe than sorry
rm() {
command rm -vI --preserve-root "$@"
}
export -f rm
pcachedir="/var/cache/pacman/pkg"
acachedir="$HOME/.cache/paru/clone"
echo "Cleaning pacman cache (keep 2 versions)..."
sudo paccache -rk2 -c "$pcachedir"
echo "Removing uninstalled pacman packages..."
sudo paccache -ruk0 -c "$pcachedir"
if [[ -d "$acachedir" ]]; then
echo "Removing cache for uninstalled AUR packages..."
fd -td -d1 . "$acachedir" --format '{/}' | rg -vxFf <(pacman -Qqm) | while read -r pkg; do
echo " Removing: $pkg"
rm -rf "${acachedir:?}/$pkg"
done
echo "Cleaning AUR build artifacts..."
fd -td -d1 . "$acachedir" | while read -r pkgdir; do
rm -rf "$pkgdir/src"
git -C "$pkgdir" clean -fqdx -e '*.pkg.tar*' 2>/dev/null
done
echo "Cleaning AUR cache (keep 2 versions)..."
fd -td -d1 . "$acachedir" -x paccache -qrk2 -c {} \; 2>/dev/null
fi
echo "Cleanup complete."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment