On Fri, May 03, 2002 at 09:09:44PM -0500, Bob Tanner wrote:
> Bob asks:
>
> > Anyone know of a tool that will "prune" old rpms from a directory? What I'm
> > referring to is something that will cruise through the /usr/src/redhat/RPMS
> > and /usr/src/redhat/SRPMS and remove all but the newest files.
>
> Clay responds:
>
> Perl is your friend.
Bah! Perl sucks. All hail the power of pipes.
for package in `rpm -qp --queryformat="%{NAME}\n" *.rpm | sort | uniq -d`; do
packages=$(rpm -qp --queryformat="%{NAME},%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}.rpm\n" ${package}* | grep ${package}, | cut -d, -f2)
while [ `echo $packages | wc -w` -gt 1 ]; do
deletenext=$(echo $packages | cut -d' ' -f1)
echo "I think I'll delete $deletenext"
packages=$(echo packages | cut -d' ' -f2-)
done
done
Add in the rm line when you're ready for it.
Nate