How can I sort packages by file size when searching the repositories?

How can I sort packages by file size when searching the repositories?

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.

答案1

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 :)

答案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.

答案3

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. :)

相关内容