Personal tools
You are here: Home Hacking archlinux pkgsize

pkgsize

display disk usage of installed packages (shell script)

Click here to get the file

Size 1 kB - File type text/plain

File contents

#!/bin/sh

# Usage:
# pkgsize [du_size_option] [package] ...

# default du_size_option: -b
# valid du_size_option: -k|-m|-b
# Using options -m,-k will lead to  unexact total values

# Example Usage 1 -> count size of all packages (Kb):
# pkgsize -k|sort -n

# Example Usage 2 -> count size of coreutils and glibc (Bytes):
# pkgsize  coreutils glibc


function getsize {
    pacman -Ql $1|cut -d " " -f 2|grep -v /$|xargs du  -c $du_opt|tail -n 1|cut -f 1
}

total=0				

if [ "${1#-*}" != "$1" ]; then 
    du_opt=$1			# du size option
    shift
else
    du_opt=-b			# default du size option: count bytes
fi

if [ $# -eq 0 ]; then
    for pkg in `pacman -Q|cut -d " " -f 1`;do
	size=`getsize $pkg`
	total=$[ $total + $size ]
	echo -e "$size\t$pkg"
    done
else
    while [ -n "$1" ]; do
	size=`getsize $1`
	echo -e "$size\t$1"	 
	total=$[ $total + $size ]
	shift
    done
fi

echo -e "$total\ttotal"




Document Actions