# How can I check how much space specific packages occupy?

I maintain a list of packages I installed on my system (using apt-get). I would like to know how much space these packages occupy, together with their dependencies if possible.

Can I use some tool for it or do I have to write my own script that would sum up all corresponding files (binaries, dynamic libraries, etc.)?

• You need to know it before installing? This log script could tell you afterwards: askubuntu.com/a/601772/72216 – Jacob Vlijm Mar 28 '15 at 22:03
• Afterwards but if I understand correctly the script you're linking will only show me the space after and before installongv a certain software. I already have all these packages installed. – syntagma Mar 28 '15 at 22:09
• Ah, I see, that is a pitty. In many cases, it will be hard to say what is what, since many libraries will be shared. It would be possible to script- see a package's size plus its dependencies, but that would therefore not necessarily be equal to the actual change in disk space when it was installed. – Jacob Vlijm Mar 28 '15 at 22:14

You can try this bash script:

#!/bin/bash
all_files=( $(dpkg -L "$1") )
for file in "${all_files[@]}"; do [ -f "$file" ] && du -h "$file" done  Pass the name of the package as first argument e.g. bash script.sh nano. dpkg -L package will list all the files installed by package, we have saved the list as an array. It will include the parent directories too, to get rid of the directories we have done a test [ -f "$file" ], so if the array element is a regular file then we will get the size of the file on the disk by du -h.

Here is a test result:

$bash check_disk.sh vlc 4.0K /usr/share/menu/vlc 4.0K /usr/share/lintian/overrides/vlc 8.0K /usr/share/applications/vlc.desktop 4.0K /usr/share/kde4/apps/solid/actions/vlc-openbd.desktop 4.0K /usr/share/kde4/apps/solid/actions/vlc-opencda.desktop 4.0K /usr/share/kde4/apps/solid/actions/vlc-opendvd.desktop 4.0K /usr/share/kde4/apps/solid/actions/vlc-openvcd.desktop 4.0K /usr/lib/mime/packages/vlc 32K /usr/lib/vlc/plugins/video_output/libxcb_xv_plugin.so 12K /usr/lib/vlc/plugins/video_output/libaa_plugin.so 28K /usr/lib/vlc/plugins/video_output/libxcb_window_plugin.so 32K /usr/lib/vlc/plugins/video_output/libgl_plugin.so 24K /usr/lib/vlc/plugins/video_output/libxcb_x11_plugin.so 12K /usr/lib/vlc/plugins/video_output/libglx_plugin.so 40K /usr/lib/vlc/plugins/video_output/libxcb_glx_plugin.so 16K /usr/lib/vlc/plugins/video_output/libcaca_plugin.so 32K /usr/lib/vlc/plugins/video_filter/libpanoramix_plugin.so 16K /usr/lib/vlc/plugins/services_discovery/libxcb_apps_plugin.so 776K /usr/lib/vlc/plugins/gui/libskins2_plugin.so 2.5M /usr/lib/vlc/plugins/gui/libqt4_plugin.so 16K /usr/lib/vlc/plugins/control/libglobalhotkeys_plugin.so 20K /usr/lib/vlc/plugins/access/libxcb_screen_plugin.so 12K /usr/lib/vlc/plugins/misc/libxdg_screensaver_plugin.so 12K /usr/lib/vlc/plugins/codec/libsdl_image_plugin.so 32K /usr/lib/vlc/plugins/codec/libvaapi_plugin.so 4.0K /usr/bin/qvlc 4.0K /usr/bin/svlc 0 /usr/share/man/man1/qvlc.1.gz 0 /usr/share/man/man1/svlc.1.gz  • Very nice +1. Only it doesn't list the dependencies. At the same time, listing dependencies is almost not possible, since many will be shared with other applications. – Jacob Vlijm Mar 29 '15 at 15:59 • @JacobVlijm: Thanks..i was thinking about the dependencies too, it would be kind of an infinite chain and also as you mention would not be a good one :) – heemayl Mar 29 '15 at 17:12 Could not resist expanding a bit, completely based on heemayl's concept, to make a script with two options: 1. Only output the (total) size of an installed package (but without its dependencies, since dependencies are practically always shared, so which package should have it on its "account"?) an example: $ check_size gimp
6644.1K


or:

1. Produce a more verbose report on the directories, the files, their sizes and total size of installed files (obviously most lines are skipped):

    $check_size gimp --verbose Directories: ==================== /usr/share/man /usr/share/man/man1 /usr/share/menu /usr/share/pixmaps /usr/share/python /usr/share/python/runtime.d Installed files: ==================== 48K /usr/lib/gimp/2.0/plug-ins/sample-colorize 5,5M /usr/bin/gimp-2.8 52K /usr/lib/gimp/2.0/plug-ins/curve-bend 52K /usr/lib/gimp/2.0/plug-ins/file-psd-load 52K /usr/lib/gimp/2.0/plug-ins/filter-pack 52K /usr/lib/gimp/2.0/plug-ins/pagecurl 52K /usr/lib/gimp/2.0/plug-ins/video 56K /usr/lib/gimp/2.0/plug-ins/color-rotate 56K /usr/lib/gimp/2.0/plug-ins/file-ps 56K /usr/lib/gimp/2.0/plug-ins/print 56K /usr/lib/gimp/2.0/plug-ins/selection-to-path Total size: ==================== 6644.1K  ### How to use 1. Copy the script below into an empty file, save it as check_size in ~/bin (or elsewhere in$PATH), without language extension.
2. Make the script executable
3. If you just created the directory ~/bin, run source .profile, or log out / in.
4. Run it by either the command:

check_size <package>


for just the size, or:

check_size <package> --verbose


for the verbose information

### The script

#!/usr/bin/env python3
import subprocess
import os
import sys

files = []; drs = []; sizes = []
get =  subprocess.check_output(["/bin/bash", "-c", "dpkg -L "+sys.argv[1]]).decode("utf-8").splitlines()
for l in get:
if os.path.isfile(l):
info = subprocess.check_output(["du", "-h", l]).decode("utf-8")
sizes.append(float(info.split()[0].replace("K", "").replace(",", ".").replace("M", "")))
files.append(info)
else:
drs.append(l)
try:
if sys.argv[2] == "--verbose":
print("\nDirectories:\n"+20*"=")
for l in sorted(drs):
print(l)
print("\nInstalled files:\n"+20*"=")
for l in sorted(files):
print(l.strip())
print("\nTotal size:\n"+20*"=")
print(str(sum(sizes))+"K")
except IndexError:
print(str(sum(sizes))+"K")