[H-GEN] dpkg statistics
Christopher Biggs
listjunkie at pobox.com
Wed Apr 2 23:46:09 EST 2003
[ Humbug *General* list - semi-serious discussions about Humbug and ]
[ Unix-related topics. Posts from non-subscribed addresses will vanish. ]
Marco Grigull <kni501ss at optushome.com.au> moved upon the face of the 'Net and spake thusly:
> Is there an easy way to tell how much diskspace each installed debian
> package uses? (its spring cleaning time again)
When looking for disk-hungry packages I generally run up aptitude or
deity and configure it to sort by the "Installed-Size" column. It
seems to be the zillions of medium-sized packages that eat the space, though.
You can also grep the info out of /var/lib/dpkg/status using the
incantation:
# grep -B4 ^Installed-Size status
Hey, whaddya know, I wrote a Perl script to do it six months ago.
I have no memory of those events; but I /never/ throw out a script.
I probably wrote this because I have some debian systems where RAM is so
tight that the package manager programs take FOREVER to sort the
package list.
The script itself is longer than need be becuase it's built on my
standard perl script boilerplate, which contains option parsing
routines, debug trace, and comment banners. The script operates as a
simple state machine; you could probably make it work by just cutting
out the bit from "Main program starts here".
It shows that on my ork desktop system, the top ten biggest packages
are actually indispensable (but ymmv):
chris at gweepery: (7) You are in ~/src/perl
So what are you going to DO about it? >./pkgsize.pl | sort -n -r | head
108332 openoffice.org-bin
53856 tetex-base
39464 tetex-extra
39088 tetex-doc
35338 emacs21-common
31784 openoffice.org
28505 emacs21-el
25272 acroread
24796 mozilla-browser
22244 gimp1.1
Cut, invoke, enjoy.
--cjb
-----------------------------------------------------------------------------
#!/usr/bin/perl
#
#@ pkgsize.pl - List sizes of installed Debian packages
#
# Copyright (C) 2002 Christopher Biggs
# Time-stamp: <2002-10-17 12:50:57 chris>
#
#@******************************* Commentary *******************************
#
# The package managers are too slow and clumsy, so I hacked this up to
# point out which packages are hogging all my disk space.
#
#@**************************** MAIN ENTRY POINT ****************************
#
#
use English;
use File::Basename;
use Getopt::Long;
use FileHandle;
#
#@@ Set default options and parse command line
#
# Note that short options are still availalbe where they are a
# unique prefix, eg -h, -d will produce help and debug respectively.
#
Getopt::Long::config('auto_abbrev');
Getopt::Long::config('bundling');
Getopt::Long::config('no_ignore_case');
%opt = ();
$opt{'debug'} = 0; # change this for intensive inhouse debug
$rc = GetOptions(\%opt, "debug|d=i", "help|h");
if (!$rc || $opt{'help'}) {
usage();
}
#
# Set up debugging
#
$DEBUG = 0;
$me = $0;
if ($opt{'debug'}) { $DEBUG = $opt{'debug'}; };
sub doDEBUG{ $fmt=shift; printf STDERR ("$me: $fmt", at _); }
sub DEBUG0 { doDEBUG(@_); }
sub DEBUG { $DEBUG && doDEBUG(@_); } # same as DEBUG1
sub DEBUG1 { ($DEBUG >= 1) && doDEBUG(@_); }
sub DEBUG2 { ($DEBUG >= 2) && doDEBUG(@_); }
sub DEBUG3 { ($DEBUG >= 3) && doDEBUG(@_); }
sub DEBUG4 { ($DEBUG >= 4) && doDEBUG(@_); }
#
#@@ Set up global variables
#
$RCS_version = '$Revision: $ ';
#
#@@ Process command line arguments
#
if ($DEBUG) {
DEBUG("<!-- Argument dump -->\n");
foreach (keys(%opt)) {
DEBUG("<!-- opt{'$_'} => %s -->\n",$opt{$_});
}
DEBUG("<!-- End of argument dump -->\n");
}
#
#@@ Process the input files
#
# Main program starts here
#
open (STATUSDB, "</var/lib/dpkg/status") or die "Can't read status database";
$package =undef;
$installed =0;
$size = 0;
while (<STATUSDB>) {
if (/^$/) {
#
# End of a package section
#
DEBUG("End of package met ($package, $installed, $size)\n");
if ($package && $installed && $size) {
#
# Print summary
#
print ("$size $package\n");
}
#
# Clear package flags
#
$package=undef;
$installed=0;
$size=0;
} elsif (/^Package: (.*)$/) {
$package = $1;
DEBUG("Package=$package\n");
} elsif ($package && /^Status:.* installed/) {
DEBUG(" $package is installed\n");
$installed = 1;
} elsif ($package && /^Installed-Size: ([0-9]+)/) {
$size = $1;
DEBUG(" $package uses $size\n");
}
}
exit 0;
#@******************************* SUBROUTINES ******************************
#
#@@--------------------------------- usage ---------------------------------
#
# Print a command usage message
#
sub usage {
print("Usage: $PROGRAM_NAME [OPTION]... [FILE]...]\n\n");
print(" --debug=N generate debug trace at verbosity n (0..4)\n");
print(" --help print this help message\n");
print("\n\n");
exit(0);
}
#end of file
--
* This is list (humbug) general handled by majordomo at lists.humbug.org.au .
* Postings to this list are only accepted from subscribed addresses of
* lists 'general' or 'general-post'. See http://www.humbug.org.au/
More information about the General
mailing list