1

In Debian when you look at a package, you get lot of info. Including the uncompressed file size of the package. Is there a way to grep through the file-listing so that packages appear either from biggest to lowest or lowest to biggest ?

This is how it appears via aptitude :-

[$] aptitude show leafpad | grep Uncompressed

Uncompressed Size: 739 k

I am sure there is a way to do the same, but how? I am on zsh.

I am looking for all available package listing and would like it in human-readable way (i.e. KB/MB/GB etc.)

Repping @Theophrastus for the effort though.

  • 1
    "grep"? well, if sorted is the key then how about this?: dpkg-query --show --showformat='${Package;-50}\t${Installed-Size} ${Status}\n' | sort -k 2 -n |grep -v deinstall – Theophrastus Nov 24 '15 at 14:28
  • What packages do you want? All installed packages? All available packages? All manually installed packages? – terdon Nov 24 '15 at 14:50
1

If I understand you right, you want something like this:

# apt-get install dctrl-tools
$ sort-dctrl -k Installed-Size:n /var/lib/apt/lists/*_Packages | grep-dctrl -ns Package,Installed-Size -

You get numbers in units of kB = 1024 bytes. Converting the output would be a separate question.

2

Using aptitude --sort parameter

Theoretically you should be able to use aptitude's search and sort facilities directly – sadly there seems to be a bug that causes aptitude to output packages with state c (deleted packages with configuration files still on the system) last and in a rather unsorted order:

aptitude -F '%p %I' search '!~v' --sort "installsize"

Where -F is used to tell aptitude how to format the output: %p is the package name, %I the estimated install size. Check out the section Customizing how packages are displayed in the aptitude reference manual if you want to learn more about how to format aptitude's output.

The search term !~v selects all non-virtual packages: ! is used for negation, and ~v selects virtual packages. Have a look at the Search Term Reference for more ways to search the package database using aptitude; for example: if you are only interested in installed packages you would use ~i.

--sort does the obvious thing of telling aptitude to sort the listing by certain criteria (a comma separated list of criteria) and installsize is the criterion for the Uncompressed/Installed size; you can invert the sort direction by prepending ~ to the criterion: ~installsize. There is a section in the aptitude manual for those, too: Customizing how packages are sorted.

Piping a package listing to sort

aptitude --disable-columns -F '%p %I' search '!~v' | sed 's/ \([^ ]\{1,2\}\)$/\1/' | sort -k2 -h | column -t

--disable-columns is necessary as to not confuse the selection of the sort column with sort's -k argument.

sed is required because the space between the size number and it's qualifier (i.e. the MB in "4,897 MB") cause sort to not pick up the qualifier for the --human-numeric-sort (-h).

After the sorting column -t will create a pretty, columnified display of the package listing.

  • Strange (using Aptitude version 0.6.3): Running aptitude -F '%p %I' search '~i' --sort "installsize" results in a list that omits about half of my installed packages, while running aptitude --disable-columns -F '%p %I' search '~i' | sed 's/ \([^ ]\{1,2\}\)$/\1/' | sort -k2 -h | column -t lists all of my installed packages(!) – Digger Jun 21 '18 at 22:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.