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!

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

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

AWS Security LIVE!

Hosted by security experts, AWS Security LIVE! showcases AWS Partners tackling real-world security challenges. Join live and get your security questions answered.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️