Pamac list: Any chance to format file sizes?

I’d like to get the total size for list like

$ pamac list -o
autoconf     2.71-1    core      2,3 MB
fakeroot     1.25.3-2  core      141,6 kB

In principle, this would work:

$ pamac list -o | awk '{ total += $4 }; END { print total }'

but the result is wrong due to different units (kB and MB in this example).
Any chance to have unique units or another possibility to calculate the total?
Thank you and regards, Michael

Well this is not stackoverflow here, but for accurate numbers you need to pull the desc files here: /var/lib/pacman/local/*/desc


export array=( $(for x in $(pamac list -o -q); do egrep -h -A1 "%SIZE%" /var/lib/pacman/local/${x}*/desc | grep -v "%SIZE%\|-"; done) )
export sum=$(IFS=+; echo "$((${array[*]}))")
echo "$(echo "${sum} / 1000000" | bc) MB" 
1 Like

Thanks a lot @megavolt, works perfect!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.