#!/bin/bash # # pbrisbin 2009 # ### N=3 # how may versions to keep -- includes installed PD="/var/cache/pacman/pkg" WD="/tmp/pacclean" rm -rf $WD mkdir -p $WD/saveme LC_ALL="C" pushd $WD &>/dev/null || exit 1 for package in $(find $PD -name *.pkg.tar.gz | sort -r); do gunzip < $package | tar -xf - .PKGINFO || exit 1 file="$package" name="$(awk '/^pkgname/ {print $3}' .PKGINFO)" vers="$(awk '/^pkgver/ {print $3}' .PKGINFO)" echo "$name $vers $file" >> $WD/all.lst done popd &>/dev/null || exit 1 pacman -Qq | while read pack; do grep -m $N ^$pack\ $WD/all.lst | awk '{print $3}' | while read file; do cp -av $file $WD/saveme/ done done echo "up to $N versions of each installed package are now in $WD/saveme" echo "please verify everything you want is there before clearing your cache" exit 0