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!

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay