list package after size in Debian/Ubuntu

I had a Ubuntu system where the root drive almost was full i suspected it was some packages that apt-get autoremove couldn’t remove, that was using the drive.

This small script will list the installed packages on your system ending with the biggest.

dpkg-query -W --showformat='${Installed-Size;10}\t${Package}\n' | sort -k1,1n

On my system this was a huge amount of old kernel images, and kernel sources that was installed.

to remove the packages i used:

apt-get remove --purge

to see the total amount of storage used and exclude the /mnt (all my discs are mounted here) use:

du -shc --exclude /mnt /*