Friday, November 9, 2007

Total installed size of a debian system

I was curious to know about the amount of space taken by packages on my server, to have an idea of the stress I give to the hard drives when I run debsums on all the packages. I used dpigs and perl to achieve this, being reasonably comfortable with the latter:

dpigs -n 300 | perl -ne 'BEGIN {$total = 0} /(\d+)/; $total += ($1 || 0) ; END { print "Total $total\n"}'

That worked, at least provided that there were less than 300 packages... I later thought about using awk, which is precisely designed for this kind of applications. That actually looks like

dpigs -n 300 | awk '{a += $1} END {print a}'

Better already. But you still need to know the number of packages installed. Well, we could ask dpkg, of course:

dpigs -n `dpkg -l | wc -l` | awk '{a += $1} END {print a}'

1 comment:

Bruce said...

You can also use dpigs -n -1. Nice script, though!