[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Are /var/cache/apt/archive files essential?

Maurits van Rees <maurits@vanrees.org> wrote:
From the apt-get manual page:




So call 'apt-get autoclean' to remove most of your packages or
'apt-get clean' to remove them all. It doesn't hurt. You just need to
fetch those files again when you have to reinstall for some reason.

Note though that having an older version of a package lying around in
the apt cache can be useful when you discover a bug in the new version
and want to revert to the old.

To have more control, cobble together some shell commands. For example
see this posting by me:


I have never been happy with the 'clean' and 'autoclean' options for apt-get. I don't want to remove the files for packages that I currently have installed. I just want to remove the old stuff. I have yet to find anything that will do this for me. That is why my /var partition also fills up until something stops working and I manually go through the directory and start deleting big files. Well, I recently got tired of that (it is tedius and inefficient) so I wrote a python script to automate a lot of it. (If I had had Maurits' scripts I probably would have been hapy with that, but now I have my own.)

The scripts looks through /var/cache/apt/archives and the output of 'dpkg -l'. It then displays some statistics about the archive, i.e.

Total installed packages
Total uninstalled packages in archive
Total packages in archive
Total files in archive
Packages in archive w/dups
Files in archive in dup pkgs

The following prompts will then be presented (taken from the program's help screen):

Delete uninstalled packages from archive (y/N/p/q)?
   y = Delete all uninstalled package files from the archives
       without prompting.
   N = Do not delete any package files based on installation status.
   p = Prompt to keep each uninstalled package file in the archive.
   q = Quit program without deleting anything.

If prompting was requested:

Keep: filename.deb (Y/n/q) ?
   Y = Keep the package file in the archives (do not delete).
   n = Delete the package file from the archives.
   q = Quit program without deleting the package file.

For each package with multiple files in the archive a list of each file
will be presented.  The list is presented in the system sort order and
an asterisk (*) is displayed before the file with the most recent date.

For the last package shown the following prompt will be presented.

Keep only filename.deb (y/N/d/q) ?
   y = Keep the listed package file (deleting all others for
       the specified package).
   N = Prompt to keep each package file.
   d = Keep only the most recent file (as indicated with an asterisk).
   q = Quit program without deleting the package file.

If prompting for package deletion was requested:

Keep: filename.deb (Y/n/q) ?
   Y = Keep the package in the archives (do not delete).
   n = Delete the package from the archives.
   q = Quit program without deleting the package.

NOTE: All responses are case insensitive and require only
      a single character.  Defaults are shown in uppercase.

      Taking all defaults WILL NOT DELETE ANYTHING!


So far, everything seems to work as expected. I have used this on both of my boxes, one is running Sarge (w/ Python 2.3) and the other is running Woody (w/ Python 2.1). There is extra code in the script to handle the older 'ls' from Woody which does not have an option to display the date in a sortable fashion, so this should work on older systems, as well as newer ones. Just the option to remove packages not listed as installed by dpkg removed 117 files on my Sarge box. All in all I have used it to free up nearly 300MB of space (the archives now take up about 492MB. Since I have 1GB in /var that is almost a third of my available space freed up.

If anyone is interested in trying this out, drop me an e-mail and I will send it out to you. I would appreciate any comments, or feedback.

Marc Shapiro

Reply to: