Created
May 18, 2015 05:23
-
-
Save kathawala/1385fcdd4bf84a88fde6 to your computer and use it in GitHub Desktop.
Removes cached packages which have 2+ more recent package versions cached
This file contains 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 | |
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