This question already has an answer here:
I would like to cleanup my local repository after each upgrade. When I add newer version of packages to
pool and regenerate indexes with
dpkg-scanpackages, program warns about old versions of packages (in case
-m option is not passed):
dpkg-scanpackages: warning: Package php5-common (filename pool/local/php5-common_5.3.6-13ubuntu3.3_amd64.deb) is repeat but newer version; dpkg-scanpackages: warning: used that one and ignored data from pool/local/php5-common_5.3.6-13ubuntu3.2_amd64.deb!
I'm looking for an automated way to safely remove old packages from disk. I'll call such a script safe if it do not delete an old package if a newer version is available and removing old version will cause an unmet dependency in local repository