Skip to content

Instantly share code, notes, and snippets.

@Juma7C9
Created July 26, 2023 19:07
Show Gist options
  • Save Juma7C9/61d09aa8c4b1ec51f9d43a8c272a34a0 to your computer and use it in GitHub Desktop.
Save Juma7C9/61d09aa8c4b1ec51f9d43a8c272a34a0 to your computer and use it in GitHub Desktop.
Simple script to delete pacman package files older than some period, printing the freed space
#!/bin/bash
CACHE_PATH=/var/cache/pacman/pkg
PRESERVE_MONTHS=3
DELETED_SIZE=$(/usr/bin/find . ! -newermt "$PRESERVE_MONTHS months ago" -ls | awk -F' ' 'BEGIN {sum=0} {sum+=$7} END {print sum}' | numfmt --to=iec-i)B
/usr/bin/echo "Deleting $DELETED_SIZE of package files older than $PRESERVE_MONTHS months..."
/usr/bin/find $CACHE_PATH ! -newermt "$PRESERVE_MONTHS months ago" -delete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment