DEV Community

gunitinug
gunitinug

Posted on

How big is my upgrade?

Say I want to upgrade my Ubuntu box but I want to find out how big the upgrade operation will be.

First, we have to find out all the packages to be installed. The -s option means it's simulation (ie. nothing will be installed).

$ apt-get -s upgrade | grep -i ^inst | awk '{print $2}' | tr '\n' ' '
base-files libnss-systemd ... xwayland mutter
Enter fullscreen mode Exit fullscreen mode

The package names are separated by a space.

Now I want to query the installed-size using dpkg-query:

$ dpkg-query -s $(apt-get -s upgrade | grep -i ^inst | awk '{print $2}' | tr '\n' ' ') | grep -i "installed-size"
Installed-Size: 392
...

Enter fullscreen mode Exit fullscreen mode

Then, just get the numbers (eg. 392) and add them all up.

$ dpkg-query -s $(apt-get -s upgrade | grep -i ^inst | awk '{print $2}' | tr '\n' ' ') | grep -i "installed-size" | awk '{print $2}' | awk '{total+=$1} END {print total}'
2649388
Enter fullscreen mode Exit fullscreen mode

What we've got is total space that will be occupied by apt-get's upgrade operation is 2649388 KB.

Now we've done the hard part. Phew! What's left is to convert 2649388 KB to GB for our convenience.

$ total=$(dpkg-query -s $(apt-get -s upgrade | grep -i ^inst | awk '{print $2}' | tr '\n' ' ') | grep -i "installed-size" | awk '{print $2}' | awk '{total+=$1} END {print total}'); bc <<< "scale=5; $total / 1024 / 1024"
2.52665
Enter fullscreen mode Exit fullscreen mode

To finish, just append GB at the end.

$ total=$(dpkg-query -s $(apt-get -s upgrade | grep -i ^inst | awk '{print $2}' | tr '\n' ' ') | grep -i "installed-size" | awk '{print $2}' | awk '{total+=$1} END {print total}'); bc <<< "scale=5; $total / 1024 / 1024" | sed 's/$/GB/'
2.52665GB
Enter fullscreen mode Exit fullscreen mode

So, I know that if I decide to upgrade my Ubuntu box, it will take up at least 2.5 GB of space!

Top comments (0)