49

I would like to have a list of the installed software on my machine, with the disk space consumed by them alongside. I would prefer to be able to order by largest/smallest, but that is not a necessity.

I am the sort of person who will install software to try it, and never clean up after myself.

As a result, my 7GB (Windows and my Data are on separate partitions, as well as a swap area) Ubuntu 11.04 partition is suffering, and has started regularly showing warning messages.

1

7 Answers 7

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

shows you a package list sorted by size

4
  • 5
    Would be better if you could mention the unit of the size too.
    – jobin
    Feb 23, 2014 at 5:32
  • Probably kilobytes Jun 25, 2014 at 14:17
  • 3
    what's ;8 in ${Installed-Size;8}?
    – n611x007
    Jul 22, 2015 at 14:56
  • 3
    @naxa: Print right aligned with a fields width of 8 Jul 22, 2015 at 15:29
25

You can do this graphically in Synaptic Install synaptic.

First ensure that you enabled the Installed Size and Download size columns (or only one if you want that one).

  • To do this, go to Settings > Preferences and choose Columns and Fonts, then tick the columns you want to see.
  • Then click OK.

Preferences window

  • Once they are enabled, you can list the packages you have installed by download/installed size by click on the column.

Columns

  • Please note: I do not have my packages listed in that way this screen shot, but it works.
2
  • This is precisely what i was looking for! Thanks a lot. Sep 20, 2011 at 20:30
  • @LewisGoddard: you're welcome.
    – RolandiXor
    Sep 20, 2011 at 20:33
19

Preferred solution

I have found a shorter answer, not requiring aptitude:

dpkg-query -Wf '${Installed-size}\t${Package}\n' | column -t

Old proposed solution

The show command of aptitude is able to show the installed size of a package.

I have this little script, that make use of aptitude (to install separately) to have a list of all installed packages with sizes:

#!/bin/bash

export LC_ALL=C

aptitude show $(dpkg-query -Wf '${Package}\n') |
  awk '$1 == "Package:"     { name = $2 }
       $1 == "Uncompressed" { printf("%10s %s\n", $3, name) }' |
  awk '$1 ~ /k/ { $1 *= 1 }; $1 ~ /M/ { $1 *= 1024 }
       { printf("%9d %s\n", $1, $2)}'

Size are expressed in kilobytes, and are approximate, as returned by aptitude show pkg.

The script can be improved using a single awk invocation (but I'm lazy :-)

4
  • 1
    You might want to throw a pipe to sort -nk1 on the end of that first command. Sep 20, 2011 at 19:19
  • @MarcoCeppi: yeah, it was not the main concern of the OP, and I usually leave out ordering from my scripts, given that it may be applied in different ways as needed.
    – enzotib
    Sep 20, 2011 at 21:51
  • 1
    This also lists software that is not installed anymore. Is there a way to remove these from the output?
    – rumpel
    Jul 29, 2012 at 17:15
  • Is you want a sum of these packages pipe that first command to cut -f 1 | paste -sd+ | bc. It's also possible to grep before cut so you can get installed size of only specific packages.
    – MeanEYE
    Jun 8, 2013 at 7:05
6

Another option is to use the dpigs application from the debian-goodies package:

NAME
   dpigs - Show which installed packages occupy the most space

SYNOPSIS
   dpigs [options]

DESCRIPTION
   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).

OPTIONS
   -h, --help
       Display some usage information and exit.

   -n, --lines=N
       Display the N largest packages on the system (default 10).

   -s, --status=FILE
       Use FILE instead of the default dpkg status file (which is /var/lib/dpkg/status
       currently).

   -S, --source
       Display the largest source packages of binary packages installed on the system.
3

You can view such a list in the terminal-based package manager Aptitude:

  1. Open Aptitude with sudo aptitude.
  2. Hit S (capital S) and type ~installsize at the prompt. (The ~ is for descending sort; you can omit it if you want the smallest packages on top.)
  3. By now, packages are sorted by size inside each hierarchical level. To get an overview, you'll want as few levels as possible. Hit G and enter status at the prompt. Now all installed packages are in a single section, sorted by size.
1

The other answers here list both installed and deinstalled packages.

The following lists only those which are currently installed:

dpkg-query -W -f='${Installed-Size;8}\t${Status;1}\t${Package}\n' | grep -v "\sd\s" | sort -n | cut -f1,3-

What it does:

  1. Query the installed size, status and name of all packages
  2. Filter out deinstalled packages
  3. Cut the status column from the output

Output resembles:

...
22376   vim-runtime
26818   linux-image-3.8.0-32-generic
28673   libc6-dbg
35303   libpython3.3-dev
40303   valgrind
40731   linux-firmware
41516   smbclient
58704   linux-headers-3.8.0-26
58733   linux-headers-3.8.0-32
93566   linux-image-extra-3.8.0-32-generic
0

Here's a variation of Drew Noakes's answer but with awk doing the heavy lifting:

#!/bin/sh    
    
dpkg-query --show --showformat='${Package}\t${Installed-size}\t${Status}\n' |    
    awk '    
{    
    # evaluate installed packages only
    if($3 == "install"){    
        packages[$1] = $2    
    }    
}    
    
END {    
    # sort packages by size (change 'asc' to 'desc' to reverse the order)
    PROCINFO["sorted_in"] = "@val_num_asc"
    for (i in packages){    
        printf "%05.2fM | %s\n",
        packages[i] / 1024, # convert from kilobytes to megabytes
        i    
    }    
}    
' 

The output

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .