how much space does a given package, and dependencies, cost?

given a package name, I want to find how much space would be freed up if the package, and its dependencies, were deleted.

As dependencies might be shared between packages, maybe the right way to put it is: How much space does a package take, including all dependencies that are only beeing used by this package

I would prefer CLI solutions, because I would use them in scripts


Solution 1:

Simplest and bug free way to get the space used by a program and all its dependencies is to use apt itself. Note dependencies that are not used by another program, but installed with a package, is not considered as they are not removed.
Simply

sudo apt-get --assume-no autoremove PACKAGENAME

or

apt-space-used-by() { sudo apt-get --assume-no autoremove $@ | grep freed | cut -d' ' -f4-5 ;}

usage apt-space-used-by PACKAGENAME

This python script looks promising (bigpkg - find packages that require a lot of space on your system)

Solution 2:

  • Simply try following command ( to get disk space freed by purge):

    echo -n | sudo apt-get purge <package> | grep "disk space will be freed"
    

    or

    echo -n | sudo apt-get purge --auto-remove <package> | grep "disk space will be freed"
    

    where replace <package> with your package-name ( example: gimp)

    This will not purge package with dependencies but only gives how much disk space will be freed with help of grep!


  • Using dpkg --print-avail or apt-cache show:

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

    or

    dpkg --print-avail <package> | grep "Installed-Size"
    

    This will display installed size of <package>.

    Example:

    $ apt-cache show gimp | grep "Installed-Size"
    Installed-Size: 15024
    

  • Sort list of installed packages by size

    dpkg-query -W -f='${Installed-Size;8}  ${Package}\n' | sort -n
    

    You can use more for page-wise:

    dpkg-query -W -f='${Installed-Size;8}  ${Package}\n' | sort -n | more
    

    Above list packages according to size acceding, you can use tail to list packages consuming top size as follows:

    dpkg-query -W -f='${Installed-Size;8}  ${Package}\n' | sort -n | tail
    

  • Using dpigs (from man dpigs):

    dpigs - Show which installed packages occupy the most space

     dpigs sorts the installed packages by size and outputs the largest ones. Per default dpigs displays the largest 10 packages. You can change
       this value by using the -n option (see "OPTIONS"). The information is taken from the dpkg status file with grep-status(1) 

    This Can be installed by: sudo apt-get install debian-goodies
    Example of run command

    $ dpigs
    115449 wine1.6-i386
    110356 linux-image-extra-3.13.0-24-generic
    103828 libreoffice-core
    86240 fonts-horai-umefont
    74016 libreoffice-common
    72709 liboxideqtcore0
    61736 linux-headers-3.13.0-24
    60821 libpyzy-1.0-0
    59477 firefox
    59443 thunderbird
    

  • Finding size of Unused package:-

    popularity-contest (8) - list the most popular Debian packages
    popcon-largest-unused (8) - List size of unused packages
    

    First run popularity-contest and then popcon-largest-unused, This will help you to find size of unused package. Visit man-pages for more information.


I tried my best to provide useful commands by steps.
Hope these helps!