How to determine the size of a package while using apt prior to downloading?

In the terminal, for a single package:

apt-cache --no-all-versions show $package | grep '^Size: '

for more than a package:

apt-cache --no-all-versions show $packages | 
    awk '$1 == "Package:" { p = $2 }
         $1 == "Size:"    { printf("%10d %s\n", $2, p) }'

I have no idea about Synaptic.


apt-cache show <package> or aptitude show <package> will show more information about a package, including its size.

For the package size only, you can use:

apt-cache show <package> | grep Installed-Size

or

aptitude show <package> | grep 'Uncompressed Size'

For .deb packages you can use:

dpkg-deb -I <package>.deb | grep Installed-Size

This is also right but size is displayed in bytes. And this shows size in better format but if package is of very small size (say < 1MB) then in-spite of echo 'n'it will install package (Because in that case, apt doesn't prompt).

So, You use --no-download with --assume-no as follows:

sudo apt-get --no-download --assume-no install <package_name> | grep 'Need to get'

Here --no-download argues not to download package and --assume-no is for assuming no (n) in case of any prompt.

Example:

$ sudo apt-get --no-download --assume-no install ttf-devanagari-fonts 2>/dev/null | grep 'Need to get'
Need to get 938 kB of archives.