In this tutorial, I'll take you through the steps to show installed package size on Ubuntu/Debian Linux systems. This can be important when doing space audit trying to find packages using occupying large space on your system.
The Ubuntu / Debian dpkg-query and dpkg package manager provides some command line options which can be utilized for this task, with the help of some Linux regex tools like awk, sed, sort, tr etc.
Show Installed Package Size using Wajig
Another program you can use to list package size space is Wajig. Wajig is a simplified command line administrator for Debian / Ubuntu packages. This tool can be installed using the commands:
$ sudo apt-get install wajig
To list largest installed packages in descending order, use the command:
# wajig large Package Size (KB) Status =================================-==========-============ libc6 10,508 installed grub-common 11,484 installed linux-headers-3.13.0-32-generic 12,999 installed linux-headers-3.13.0-143-generic 13,216 installed iso-codes 15,207 installed perl-modules 16,134 installed perl 17,320 installed vim-runtime 25,186 installed linux-image-3.13.0-32-generic 41,029 installed linux-image-3.13.0-143-generic 43,054 installed linux-headers-3.13.0-32 61,797 installed linux-headers-3.13.0-143 62,064 installed linux-firmware 124,150 installed linux-image-extra-3.13.0-32-generic 148,283 installed linux-image-extra-3.13.0-143-generic 150,240 installed
From the output above, the package which utilizes the largest space on my Ubuntu server is Linux-image-extra-3.13.0-143-generic which is 150Mb in size.
Show Installed Package Size using dpkg-query
You can also use the dpkg-query command to list installed package filtered by size. The dpkg-query is a tool used to show information about packages listed in the dpkg database. You have to use the options -Wf
and pipe the output to sort command to get the output sorted in order.
# dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n | tail -n 10 23508 git 26870 vim-runtime 30094 libicu55 32502 cassandra 65367 linux-image-4.4.0-87-generic 68901 linux-headers-4.4.0-87 75176 snapd 97190 openjdk-8-jre-headless 148663 linux-image-extra-4.4.0-87-generic 207968 linux-firmware
You should notice that this output is similar to one from the wajig command. The last file listed is the largest.
Show Installed Package Size using dpigs
Dpigs is a Debian tool that's used to show which installed packages occupy the most space on the system. dpigs sort the installed packages by size and output the largest ones, the default number of packages displayed is 10.
This tool is not installed by default, installing it on Ubuntu / Debian system using the command.
# apt-get install debian-goodies
The run:
# dpigs 150240 linux-image-extra-3.13.0-143-generic 148283 linux-image-extra-3.13.0-32-generic 124150 linux-firmware 93841 libboost1.54-dev 62064 linux-headers-3.13.0-143 61797 linux-headers-3.13.0-32 54539 openjdk-7-jre-headless 43054 linux-image-3.13.0-143-generic 41029 linux-image-3.13.0-32-generic 39210 python-neutron
Show Installed Package Size using /var/lib/dpkg/status and awk
You can also use awk to read data from /var/lib/dpkg/status and filter it to get the size of each package installed on your system. For this, use the command below.
# awk '{if ($1 ~ /Package/) p = $2; if ($1 ~ /Installed/) printf("%9d %s\n", $2, p)}' /var/lib/dpkg/status
You can filter the output further by piping it to the sort and tail|head command.
# awk '{if ($1 ~ /Package/) p = $2; if ($1 ~ /Installed/) printf("%9d %s\n", $2, p)}' /var/lib/dpkg/status | sort -n | tail
The above command will show you package sizes in ascending order - From smallest to the largest.
There are other commands you can use but all do the same thing. This should give you enough information to get started. You can write your own functions/aliases or bash scripts using the same commands for quick execution and reference.