#!/usr/bin/php 3, 'redis' => 1, 'composer' => 1, ]; if (isset($_SERVER['argv'][1])) { $keep = (int)$_SERVER['argv'][1]; } if (!$keep) { printf("\nusage %s number [ trash_path ]\n\n", $_SERVER['argv'][0]); die("Number to keep is missing\n"); } if (isset($_SERVER['argv'][2])) { $dest = $_SERVER['argv'][2]; if (!is_dir($dest)) { die("$dest is not a directory\n"); } } $rpms = []; foreach (glob("*.rpm") as $name) { $info = rpminfo($name); $i = $info['Name']; if (isset($multi[$i])) { $i .= "/" . substr($info['Version'], 0, $multi[$i]); } $rpms[$i][$info['Version']] = $name; } foreach($rpms as $rpm) { if (count($rpm) > $keep) { uksort($rpm, "rpmvercmp"); $i = count($rpm) - $keep; while ($i--) { $name = array_shift($rpm); echo "\t$name\n"; if ($dest) rename($name, "$dest/$name"); } } }