How to list rpm packages/subpackages sorted by total size

Posted by smci on Super User See other posts from Super User or by smci
Published on 2012-11-30T02:28:26Z Indexed on 2012/11/30 5:10 UTC
Read the original article Hit count: 512

Filed under:
|
|
|

Looking for an easy way to postprocess rpm -q output so it reports the total size of all subpackages matching a regexp, e.g. see the aspell* example below. (Short of scripting it with Python/PERL/awk, which is the next step)

(Motivation: I'm trying to remove a few Gb of unnecessary packages from a CentOS install, so I'm trying to track down things that are a) large b) unnecessary and c) not dependencies of anything useful like gnome. Ultimately I want to pipe the ouput through sort -n to what the space hogs are, before doing rpm -e)

My reporting command looks like [1]:

cat unwanted | xargs rpm -q --qf '%9.{size}  %{name}\n'  > unwanted.size

and here's just one example where I'd like to see rpm's total for all aspell* subpackages:

  root#  rpm  -q --qf '%9.{size}  %{name}\n' `rpm -qa | grep aspell`
  1040974               aspell
 16417158               aspell-es
  4862676               aspell-sv
  4334067               aspell-en
 23329116               aspell-fr
 13075210               aspell-de
 39342410               aspell-it
  8655094               aspell-ca
 62267635               aspell-cs
 16714477               aspell-da
 17579484               aspell-el
 10625591               aspell-no
 60719347               aspell-pl
 12907088               aspell-pt
  8007946               aspell-nl
  9425163               aspell-cy

Three extra nice-to-have things:

  1. list the dependencies/depending packages of each group (so I can figure out the uninstall order)
  2. Also, if you could group them by package group, that would be totally neat.
  3. Human-readable size units like 'M'/'G' (like ls -h does). Can be done with regexp and rounding on the size field.

Footnote: I'm surprised up2date and yum don't add this sort of intelligence. Ideally you would want to see a tree of group->package->subpackage, with rolled-up sizes.

Footnote 2: I see yum erase aspell* does actually produce this summary - but not in a query command.

[1] where unwanted.txt is a textfile of unnecessary packages obtained by diffing the output of:

yum list installed | sed -e 's/\..*//g' > installed.txt
diff --suppress-common-lines  centos4_minimal.txt installed.txt  | grep '>'

and centos4_minimal.txt came from the Google doc given by that helpful blogger.

© Super User or respective owner

Related posts about linux

Related posts about centos