Skip to content

Instantly share code, notes, and snippets.

@eboye
Created July 23, 2025 17:51
Show Gist options
  • Save eboye/1013d65e9662620a646b060a9d7f39c8 to your computer and use it in GitHub Desktop.
Save eboye/1013d65e9662620a646b060a9d7f39c8 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# list‐desktop‐apps.sh
# Requires: apt-rdepends
# Prints: package<TAB>total-size-in-MiB (including all Depends)
set -e
# 1) find all packages that install a .desktop file
mapfile -t desktop_pkgs < <(
dpkg-query -S /usr/share/applications/*.desktop 2>/dev/null \
| cut -d: -f1 \
| sort -u
)
# 2) for each desktop package, get its full DEPENDS tree, sum Installed-Size
for pkg in "${desktop_pkgs[@]}"; do
# collect recursive Depends (no Recommends, no Suggests, only installed ones)
mapfile -t deps < <(
apt-rdepends --state-follow=Installed --follow=DEPENDS \
--no-recommends --no-suggests "$pkg" 2>/dev/null \
| grep -v '^ '
)
# include the package itself & uniquify
mapfile -t allpkgs < <(printf "%s\n%s\n" "${deps[@]}" "$pkg" | sort -u)
# now sum Installed-Size for each pkg (in KiB)
total_kib=0
for p in "${allpkgs[@]}"; do
# dpkg-query gives size in KB
size_kib=$(dpkg-query -W -f='${Installed-Size}\n' "$p" 2>/dev/null || echo 0)
total_kib=$(( total_kib + size_kib ))
done
# convert to MiB with one decimal
total_mib=$(awk "BEGIN {printf \"%.1f\", $total_kib/1024}")
printf "%-30s %6s MiB\n" "$pkg" "$total_mib"
done | sort -k2 -h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment