Estimate installed size of pacman repository

Some time ago on #artix IRC channel popped up a question on how to get the installed size of all packages in given repository and I together with other people on the channel created a one liner in shell to do exactly that.

But before I have to mention that Pacman prints the “Installed size” value when we try to install packages. So one way is to try to install all packages but this can also include dependencies and may require some pacman magic which I am not aware of. I forgot to mention, this method may require root access or sudo privileges which is not good enough for me.

There was also one more brute-force idea which consisted of downloading of all packages and checking their uncompressed sizes and counting this value somehow.This is way too brutal.

The basic idea behind this script is based on the fact that pacman prints the installed size value when we run pacman -Si "package"and as such it can be automated with bit of skill and luck.

$ pacman -Si pacman
Repository      : system
Name            : pacman
Version         : 5.2.2-1
Description     : A library-based package manager with dependency support
Architecture    : x86_64
URL             : https://www.archlinux.org/pacman/
Licenses        : GPL
Groups          : base-devel
Provides        : libalpm.so=12-64
Depends On      : bash  glibc  libarchive  curl  gpgme  artix-mirrorlist  artix-keyring  archlinux-mirrorlist  archlinux-keyring
Optional Deps   : perl-locale-gettext: translation support in makepkg-template
Conflicts With  : None
Replaces        : None
Download Size   : 838,79 KiB
Installed Size  : 4538,70 KiB
Packager        : Artix Build Bot <jenkins@artixlinux.org>
Build Date      : Št  2. júl 2020, 00:28:07
Validated By    : MD5 Sum  SHA-256 Sum  Signature

So all we need to do is get this information out of this output. This can be done with few commands or some smart awk or whatever you are good at using. The tricky part is to get the actual size because it has different prefixes we need a bit smarter tool to count formatted sizes like numfmt (this tool is truly great and I am happy it was recommended to me after I use awk script which I stole from something else) or some smart awk.

After adding a bit of counting magic and formating the result into human readable format I thought “I am done” (how foolish of me).
During the creation of this script I did not realize i was working with my local locale and thus the number formatting was totally messed up and I reflected this mess with few sed replacements in the script which made a mess when run in universal locale LC_ALL=C.

Well, I do not wish to write about every little change which I made and everything which was done, if you wish for a bit more detail you can only regret since you probably do not have logs from that channel.

So here is the final script, which is a bit of shell magic and I know that it can be improved, but it is good enough to run it from time to time and just for fun.

$ export LC_ALL=C && pacman -Sl system | cut -d" " -f2 | xargs pacman -Si | grep -i "installed size" | cut -d: -f2 | sed "s/\s//;s/ //;s/B//;s/i//" | numfmt --from=iec | paste -sd+ - | bc | numfmt --to=iec-i -- && export LC_ALL=

Example output:

2.9Gi

This script as it is written here will show the installed size of all packages in Artix system repository. It can be adapted to show some other package group or repository.

The result is nice and it works just fine, for me that is. As a bonus I learnt some nice utilities a way to use them, for me this was a win.

That is enough of my rumbling.

Articles from blogs I follow:

Why is your open source project still hosted on GitHub?

Perhaps the younger generation don't know anything about the past "evils" of Microsoft and naively believe that Microsoft is now the good friend to open source, but the truth is that all Microsoft acquisitions of open source projects is a busi…

via unixdigest.com May 22, 2025

StarFive VisionFive v2 and FreeBSD

This week I powered up the StarFive VisionFive v2 board that I have. I figured I would give FreeBSD another whirl on it, in the vague hope that RISC-V boards are a more cohesive family than ARM boards were five years ago. tl;dr: I didn’t get it to work as…

via [bobulate] May 20, 2025

Steve Ballmer was an underrated CEO

There's a common narrative that Microsoft was moribund under Steve Ballmer and then later saved by the miraculous leadership of Satya Nadella. This is the dominant narrative in every online discussion about the topic I've seen and it's a commo…

via danluu.com October 28, 2024

Generated by openring