5

I'm trying to look at some statistics on the size of packages in the Ubuntu repositories, and I'm hoping to sort my searches of packages in the repositories by file size. Is there a command that will let me look at file sizes of packages in the repositories/cache, sort them by file size, etc? `apt-cache stats' doesn't provide all the information I'd like.

I'm interested in only the official repositories at the moment, and I'm interested in sorting all packages in the repositories, not simply the ones I have installed.

4
  • If the solution I proposed works for you, could you please accept this answer? Thanks! Nov 30, 2012 at 1:25
  • @MartinOrda Patience... My office computer does not run Ubuntu, and I won't be back in my flat and able to test your answer for a while. If it works, I will accept it once I have a chance to test it. Nov 30, 2012 at 1:30
  • 1
    Of course, that's why I asked for it on the provision that it works for you :) I'm not in a rush. Nov 30, 2012 at 1:47
  • @MartinOrda Worked perfectly! Nov 30, 2012 at 4:45

3 Answers 3

3

That should work:

apt-cache -f dumpavail | \
egrep '^Package:|^Size:' | \
sed -e 's,Size: ,,' -e 's,Package: ,\n,' | \
awk '{RS=""; FS="\n"} {print $1, $2}' | \
sort -k2 -n

I'm not proud of it but that was done in a bit of a hurry :)

0
2

for installed packages you can either use a oneliner:

dpkg-query -W --showformat='${Installed-Size;10}\t${Package}\n' | sort -k1,1n

or third-party tools like wajig:

sudo aptitude install wajig
wajig large

this will give output like

...
libreoffice-core                   117,412      installed
google-chrome-stable               136,744      installed
linux-image-3.2.0-23-generic       145,113      installed
linux-image-3.2.0-33-generic       145,872      installed
nvidia-current                     179,133      installed

for searches something like this might help:

aptitude search vnc -F "%p %I"

This gives output like:

$ aptitude search xvnc -F "%p %I"
linuxvnc                71.7 kB 
linuxvnc:i386           66.6 kB 
xvnc4viewer             430 kB  
xvnc4viewer:i386                400 kB 

the %I shows the "installed" size of the archive. Now you have the ability to use sort to sort the results as you wish.

1
  • Thank you for the tips, but I'm interested in any packages in the repositories, not just the ones I have installed. Nov 29, 2012 at 13:17
0

An alternative to Marcin's solution is this oneliner (only tested in zsh):

apt-cache dumpavail \ | sed -nE '/^(Package|Size):/s/.* //p' \ | while read name; do read size echo $size $name done \ | sort -nr

It has the dubious advantage of only using sed and sort, not also grep and awk. :)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .