#580939 clean out all the archives except the .debs of installed packages

Package:
apt
Source:
apt
Description:
commandline package manager
Submitter:
Date:
2011-11-29 23:30:10 UTC
Severity:
wishlist
#580939#5
Date:
2010-05-10 00:17:26 UTC
From:
To:
Of the various clean and autoclean commands mentioned on the apt-get and
aptitude man pages, and APT::Clean* options, there is no way to
->clean out all the archives except the .debs of installed packages<-.
E.g., autoclean will also leave uninstalled .debs, if they are in
Packages files.

(There probably is a way: move all the package lists away for a moment
then run autoclean with APT::Clean-Installed=false; But that is a hack.)

#580939#10
Date:
2011-11-29 23:26:31 UTC
From:
To:
Yes, similar to clean and autoclean, there should be a function to remove all
archives except of currently installed packages.

Here is what I cobbled together to do it by hand.

$ cat Makefile
S=/var/lib/dpkg/status
death:/tmp/deathlist;set -e; cd /var/cache/apt/archives; df .;xargs rm < $?; df .
/tmp/installed:$S;apt-show-versions|sed 's!/.*!!' > $@
/tmp/archives:;ls /var/cache/apt/archives|perl -pwle 's/_.*/ $$_/' |sort > $@
/tmp/deathlist:/tmp/archives /tmp/installed
	join -v 1 $?|perl -anwle 'for($$F[1]){print if defined}' > $@

Of course I ran it just after an autoclean with APT::Clean-Installed
true... to make the join have no double matches...