Skip to content

Instantly share code, notes, and snippets.

@benruijl
Created January 24, 2012 15:46
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benruijl/1670778 to your computer and use it in GitHub Desktop.
Save benruijl/1670778 to your computer and use it in GitHub Desktop.
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