Sometimes I find myself wondering how big an installed RPM’s files really are. Use a simple script to do all of the calculating of file sizes, plus see how to recreate the RPM from the system where the package is installed in the latest addition to Linux Just Does That.

So first a refresher on the basics. Once a package is installed getting a list of files that it put on the filesystem (at least that were stored within the RPM) can be done with a simple ‘rpm’ command:

rpm -ql MozillaFirefox


And away it goes listing files forever, which is a nice start. For the curious you can add a ‘p’ on the end of ‘-ql’ and then point to an RPM package file and get the listing of files from within it before actually installing it. With this fine listing of files finding out the file size shouldn’t be too hard, so let’s tackle that next. For this I created a small script that loops through the results and calculates their size:

for j in `rpm -ql MozillaFirefox | xargs ls -ld | grep -v 'drwx' | grep -v 'lrwx' | awk '{print $5}'`; do
  i=`echo $i+$j | bc -l`;
echo $i;
unset i j

This can all be combined into one command (or better ways may be found) but basically this gets the file listing, gets output that is not recursive in nature from ls (which happens to show the sizes of the data as well as the object type (directory, file, symlink, etc.)), and then loops through all of those file sizes adding them up. This is a bit of a hack and could need manipulation per implementation of ‘ls’ (some of them, like SUSE’s, have default options applied while others may not). A better way of getting the size, for instance, would likely be to use `stat –format=%s` and then only run that against files (not directories).

So there is a more-elegant solution in my opinion, and it also lets you recreate the package from which your software was installed even if you have since deleted it. RPM itself provides the ability to recreate packages with the (you’ll never guess) –repackage option. How does this work? Simply:

rpm -e --repackage MozillaFirefox

One thing to note is that the –repackage option is used while erasing packages. This happens so that RPMs can be rolled back to a previous version after an update does not fix a problem or causes new problems. As a result if you do not want to erase the package while generating an RPM from it be sure to keep this in mind or reinstall the RPM after repackaging it (which would leave the old RPM file behind as always).

This repackage option does include the scripts for install/removal that the original RPM had as those are stored in the RPM database and as a result the resulting RPM should be very close (if not identical) to what you had before. The completed size of the RPM should be approximately the same as the size of the files on disk plus the extra package information and scripts as stored by the RPM format.

(Visited 1 times, 1 visits today)
Category: SUSE Linux Enterprise Desktop, Technical Solutions
This entry was posted Friday, 21 August, 2009 at 2:20 pm
You can follow any responses to this entry via RSS.

Leave a Reply

Your email address will not be published. Required fields are marked *

No comments yet