Skip to content

Instantly share code, notes, and snippets.

@kou1okada
Last active January 11, 2022 11:52
Show Gist options
  • Save kou1okada/abe00e842b7b6a3784300739c4d023f5 to your computer and use it in GitHub Desktop.
Save kou1okada/abe00e842b7b6a3784300739c4d023f5 to your computer and use it in GitHub Desktop.
dpkg-installedsize: Show installed sizes of each installed deb package.

dpkg-installedsize: Show installed size of each installed deb package.

Usage

Usage: dpkg-installedsize [OPTIONS]
Options:
  -f FMT       Set format (default: "%'9d KiB\t%s\n")
  -n           Sort with package name
  -s           Sort with installed size

License

MIT license.

#!/usr/bin/env bash
# dpkg-installedsize: Show installed size of each installed deb package.
# Copyright (c) 2018. Koichi OKADA. All rights reserved.
# This script destributed under the MIT license.
function usage ()
{
cat <<-EOD
Usage: ${0##*/} [OPTIONS]
Options:
-f FMT Set format (default: "${FMT}")
-n Sort with package name
-s Sort with installed size
EOD
}
function error () # [messages]
{
echo -e "\e[31;1mError: \e[0m$@"
}
FMT="%'9d KiB\t%s\n"
SORT=( cat )
while [[ 0 < $# ]]; do
case "$1" in
-f)
FMT="$2"
shift
;;
-n) SORT=( sort -k2 ) ;;
-s) SORT=( sort -n ) ;;
-h|--help)
usage
exit 0
;;
*)
error "unknown_option: $1"
exit 1
;;
esac
shift
done
dpkg-query -Wf='${Installed-Size}\t${Package}\n' \
| "${SORT[@]}" \
| xargs printf "$FMT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment