#!/usr/bin/perl # Prints a list of the largest packages when # about to execute a 'apt-get upgrade', especially # helpful for us poor souls on dial-up. A quick # un-install of an un-wanted package can save # *tons* of download time. # # Paul Boin pboin@intertechconsulting.net $cvsId = q$Id: apt-topten,v 1.3 2004/04/05 21:34:57 paul Exp $; use strict; use warnings; use Getopt::Std; my %packages; my %options; my $i = 0; get_options(); get_packages(); &print_tops($options{n}); exit; sub print_tops(){ my $number = shift; my $package; my $i; my @sorted_by_size; print "Package" . ' ' x 23 . "Bytes\n"; print '=' x 60 . "\n"; foreach $package (sort {$packages{$b} <=> $packages{$a}} keys %pac +kages) { push @sorted_by_size, ($package . (' ' x (30 - length($package +))) . $packages{$package}); } for ($i=0; $i<$number; $i++){ print "$sorted_by_size[$i]\n"; } } sub get_packages { my $list = `apt-get -u -V --trivial-only upgrade 2> /dev/null`; my $capture = 0; while ($list =~ /^(.*)$/gm){ my $line = $1; if ($capture){ if ($line !~ /^\ \ \ /){$capture = 0;next;} $line =~ m/^\ \ \ (\S+).*?=>\ (.*)\)$/; $packages{$1} = get_package_size($1,$2); } if ($line =~ /will be upgraded/){$capture = 1;} } } sub get_package_size { my $name = shift; my $ver = shift; my $cmd = "apt-cache --no-all-versions show $name"; my $result = `$cmd`; $result =~ /^Size:\ (.*)$/m; return $1; } sub get_options { my $usage = qq{Usage: $0 options -h : This help message. -n : Number of packages to list (Default = 10) Prints a list of the largest packages that 'apt-get upgrade' wants to download. } . "\n"; getopts('n:h', \%options); die $usage if $options{h}; $options{n} ||= 15; }

In reply to apt-topten by pboin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.