Perl is your friend.
(NOTE: This is just an example I whipped up in a few minutes. I will not be responsible for any data loss)
#!/usr/bin/perl
$dir=".";
opendir(DIR, $dir);
while (defined ($_=readdir(DIR))) {
next unless /rpm$/;
/^(\w+)/;
$pre=$1;
$files{$pre}{$_}=$_;
}
foreach $pre (sort keys %files) {
$num = scalar keys %{$files{$pre}};
foreach $file (sort keys %{$files{$pre}}) {
$num--;
print "Deleting $files{$pre}{$file}\n" if $num;
unlink $files{$pre}{$file} if $num;
}
}
On Thu, 25 Apr 2002, Bob Tanner wrote:
> 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.
>
> After build rpms, you end up with things like:
>
> kernel-2.4.7-10.i686.rpm
> kernel-2.4.7-19.i686.rpm
> kernel-2.4.9-21.i686.rpm
> kernel-2.4.9-31.i686.rpm
> kernel-2.4.18-22.i686.rpm
>
> Ditto in the SRPMS directory.
>
> So something that would remove all but the kernel-2.4.18-22.i686.rpm would be
> nice.
>
> _______________________________________________
> Twin Cities Linux Users Group Mailing List - Minneapolis/St. Paul, Minnesota
> http://www.mn-linux.org
> tclug-list at mn-linux.org
> https://mailman.mn-linux.org/mailman/listinfo/tclug-list