Skip to content

Instantly share code, notes, and snippets.

@benruijl benruijl/unused.sh
Created Jan 24, 2012

Embed
What would you like to do?
unused: finds unused package on your Arch Linux box
shopt -s extglob
declare -A access
access=();
cutoff=$(date +%s -d "1 week ago");
packages=$(pacman -Ql | tail -n 5000);
IFS=$'\n'
for package in $packages; do
pname=$(echo $package | cut -f1 -d' ');
pfile=$(echo $package | cut -f2 -d' ');
if [ ! -f $pfile ]; then
continue;
fi
if [[ ${access[$pname]} -gt $cutoff ]]; then
continue;
fi;
access_date=$(stat --format="%X" $pfile);
if [[ $access_date -gt ${access[$pname]} ]]; then
access[$pname]=$access_date;
fi;
done;
for I in ${!access[*]}; do
if [[ ${access[$I]} -lt $cutoff ]]; then
echo $I ${access[$I]};
fi;
done |
sort -k2 |
gawk '{ printf "%-20s %s\n", $1, strftime("%x %T", $2) }';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.