Last active
February 3, 2026 06:58
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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