Skip to content

Instantly share code, notes, and snippets.

@kathawala
Created May 18, 2015 05:23
Show Gist options
  • Save kathawala/1385fcdd4bf84a88fde6 to your computer and use it in GitHub Desktop.
Save kathawala/1385fcdd4bf84a88fde6 to your computer and use it in GitHub Desktop.
Removes cached packages which have 2+ more recent package versions cached
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
x="zzzzz"
copies=()
CLEAN_DIR="/var/cache/pacman/pkg"
for f in "$CLEAN_DIR"/*; do
name=$(echo "$f" | sed 's/[0-9\.\-]*//g')
if [[ "$name" == "$x" ]]; then
copies+=("$f")
if [[ ${#copies[@]} == 3 ]]; then
rm ${copies[0]}
copies=("${copies[@]:1:2}")
fi
else
x="$name"
copies=()
copies+=("$f")
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment