Sorting pacman packages by size

Since my SSD is uncomfortably small and I gave Arch only 20 GB to work with, one of the earlier things I did was write a script to list pacman packages and sort them by size. This isn’t a revolutionary thing and I could just as well have copypasted an existing version from stackoverflow or something, but I still liked the idea of writing it myself.

#!/bin/bash
IFS=$'\n'

a=( $(pacman -Qi | grep -E 'Name            :|Installed Size  :' | sed 's|.*: ||') )

x=" "

y=""

for i in "${a[@]}"; do
	if [ $x == " " ]; then
		x=$i
	else
		y="$y\n$i $x"
		x=" "
	fi
done

for i in KiB MiB GiB; do
	printf $y | grep $i | sort -g
done

I’m gonna be honest, I don’t remember what half of this means anymore. But it works well enough, so I use it for cleaning up sometimes.

Leave a comment

Design a site like this with WordPress.com
Get started