Show installed yum packages by size

Show_installed_yum_packages_by_size When you pay for every GB of disc space on your server, as with an Amazon EC2 instance, you want to make sure to keep the amount of installed packages to a minimum. With Amazon EC2 (especially with EBS storage) you have 2 possibilities. Increase the EBS storage – which can be done  by following the instructions in “Increase Amazon EBS Volume” – or you can try to reduce the amount of data you have on your server.

Besides minimising the actual user data, you can also try to remove installed packages that you don’t need, but some packages are so small that it is not worth thinking of removing them. So how to find the biggest packages?

The following command queries (-q) all packages (-a) and returns the result in the format defined by “–queryformat”. The format below says to print the size as the first element of each result line:

$ rpm -qa --queryformat '%10{size} - %-25{name} \t %{version}\n' | sort -n

In detail, the “%10{size}” says that the size should be aligned right and padded by 10 characters. The “%-25{name}” sets the package name to be aligned left and padded to 25 characters. After getting the list of packages, sort will sort the result line using numeric sorting (-n):

      3687 - percona-release      	 0.0
      6745 - fipscheck-lib        	 1.2.0
      8788 - dmraid-events        	 1.0.0.rc13
     11966 - perl-Crypt-PasswdMD5 	 1.3
     13320 - libtermcap           	 2.0.8

The above is a an excerpt from the full output you would see if you ran this command.

infoWithout the numeric sort parameter, the lines would be sorted by character comparison. For example, a line starting with 20 would be sorted after the 100 as it is sorting by its characters. So 1, 10, 100, 2, 20, 200, etc, but with the numeric parameter, the sort will be based on the numeric value of the numbers and consider 20 smaller then 100 and sort it accordingly as 1, 2, 10, 20, 100, 200, …

Read more of my posts on my blog at

This entry was posted in Linux Administration and tagged , , , . Bookmark the permalink.