Identifying large packages installed on Debian by Josh Sherman

Related Articles

Last week I talked about my quick fix for freeing up disk space on the root / A partition of my Debian system. I also talked about potentially resizing my partitions at some point to help ward off the root issue / Fills up so fast.

Since the system is my daily driver during the week, I don’t necessarily want to risk an otherwise stable state.

The next best thing to just resizing the partitions was to figure out which packages I had installed that were taking up a lot of space, then figure out which ones I didn’t need.

Coincidentally, I had something similar a few months ago, I removed a bunch of language packs that were installed by default with Firefox ESR. While it’s useful to provide support for multiple languages ​​out of the box, it didn’t make long-term sense to have them around once you determine which language you’re going to use for your day-to-day activities.

Fewer packages installed means fewer packages to update in the future, and that’s a good thing.

So at this point, I cleaned mine apt I cached and removed almost every unnecessary package on my system, in addition to automatically removing the packages that the system thought were unnecessary.

But do I really need to get rid of everything I no longer need?

Although I wasn’t immediately sure if it was, I thought it would be good to see what packages I had installed and how much space they were taking up.

To achieve this, you need a pipe | A handful of commands together. The first of them is dpkg-query. If you run it with --show The command will give you a quick list of what you have installed and the package version:

Great if you want the list, not great if you want the package size. Fortunately, you can pass in --showformat argument, and tell it to show you the installed size of the package:

% dpkg-query --show --showformat='${Package;-50}t${Installed-Size}n'

We now have the package names, and their installed size, in kilobytes (KB). The next step will be to sort things, to better understand which packages are the biggest:

% dpkg-query --show --showformat='${Package;-50}t${Installed-Size}n' 
| sort -k 2 -n

Great, at the end of the list, we can see which packages are the biggest!

At this point, we actually have enough to continue identifying large packages that we may not need, such as old versions of the Linux kernel that may no longer be in use.

But, the current output contains packages that are marked for removal (if you haven’t run apt autoremove before running it). Also, it would be really nice to put the size in a more human readable format instead of just a number.

To achieve these two things, we can continue to act | Things to the side
grep and awk Then we’ll have output that looks really nice:

% dpkg-query --show --showformat='${Package;-50}t${Installed-Size}n' 
| sort -k 2 -n  # Put it in order
| grep -v deinstall  # Omit the packages scheduled for deletion already
| awk '{printf "%.3f MB t %sn", $2/(1024), $1}' # Make it pretty

As I mentioned, you may have things like old versions of the Linux kernel still floating around on your system, so you can take it one step further and preach more | grep 'linux-image' In the end, which will give you output similar to this:

0.013 MB 	   linux-image-amd64
288.112 MB 	 linux-image-5.10.0-16-amd64
302.977 MB 	 linux-image-5.10.0-20-amd64
455.689 MB 	 linux-image-6.0.0-6-amd64
483.875 MB 	 linux-image-6.1.0-2-amd64

While there isn’t a lot of space, there is roughly a void of space taken up by old photos on my system. Given the small size of my root / Partition, this is actually a non-trivial chunk.

However, I always like to keep at least one version behind the latest version available on my system, so I’ll only remove the 5.10 versions.

good things? want more?

Weekly emails about technology, development and sometimes sauerkraut.

100% Fresh, Grade A Content, Never Spam.


Popular Articles