Created
July 23, 2025 17:51
-
-
Save eboye/1013d65e9662620a646b060a9d7f39c8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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