#!/usr/bin/perl -w # Print the installed-size of Debian packages, in descending order. # Skip over anything that's in state "deinstall" ("rc" on dpkg -l). my %pkgs = (); my %skip = (); my $pkg = ""; my $size = 0; my $maxlen = 0; open (S, "< /var/lib/dpkg/status") || die "cannot open /var/lib/dpkg/status"; while () { if (/^Package:/) { (undef, $pkg) = split; $skip{$pkg} = 0; $maxlen = length $pkg if (length $pkg > $maxlen); } elsif (/^Installed-Size:/ && !$skip{$pkg}) { (undef, $size) = split; die "internal error: Installed-Size: without Package:" unless defined($pkg); $pkgs{$pkg} = $size; } elsif (/^Status: deinstall/) { $skip{$pkg} = 1; } } @sorted = sort { $pkgs{$b} <=> $pkgs{$a} } keys %pkgs; foreach (@sorted) { next unless (defined($_) && defined($pkgs{$_})); printf "%-*s %6d\n", $maxlen, $_, $pkgs{$_}; }