How to list packages by size using Aptitude

Biggest packages installed on my Ubuntu according to Aptitude
Biggest packages installed on my Ubuntu according to Aptitude

This is a query that I frequently have: how to list packages sorted by their size? I am especially interested in this about installed packages. There are other tools that can do this job, but I like to use Aptitude for this since I use it regularly anyway.

To list all available packages:

$ aptitude search ".*"

Aptitude understands the concept of the install size i.e., how much disk space the files of a package occupy after they are uncompressed and extracted from the package. So, sorting by this installsize is easy:

$ aptitude search ".*" --sort installsize

Note that this listing is in ascending order of size. So, the largest packages are listed at the end.

The problem with this listing is that Aptitude does not display the size, so we have no idea how big the install sizes are. To show that, we can tinker with the display format and get it to display the package name and install size:

$ aptitude search ".*" --display-format "%p %I" --sort installsize

Using the shorter versions of the options, this command becomes:

$ aptitude search ".*" -F "%p %I" -O installsize

Now, to list all installed packages:

$ aptitude search "~i"

Finally, to show the install size of only installed packages and sort by it, we just apply the options shown above:

$ aptitude search "~i" --display-format "%p %I" --sort installsize

Reference: Aptitude user’s manual (its man page is woefully short on details of its commands)

Tried with: Aptitude and Ubuntu 14.04

How to view information about a package in Ubuntu

A lot of information about a package can be viewed in Ubuntu. For example, the version, dependencies, description and such.

The most common way to look up information about a package is using apt-cache:

$ apt-cache show screenruler

If you are most familiar with aptitude, the command is similar with that too:

$ aptitude show screenruler

Tried with: Ubuntu 14.04