Deletes ~/.cargo cached data older than 2 weeks
| #!/usr/bin/env bash | |
| ## Deletes ~/.cargo cached data older than 2 weeks | |
| set -eu | |
| du_before=$(du -hd0 ~/.cargo/ | cut -f1) | |
| # remove old crate caches & sources | |
| find ~/.cargo/registry/cache/ -type f -ctime +13 -atime +13 -delete | |
| find ~/.cargo/registry/src/ -type f -ctime +13 -atime +13 \ | |
| | cut -d'/' -f1-8 | sort | uniq | grep . \ | |
| | xargs -n1 rm -rf | |
| # remove old git checkouts | |
| find ~/.cargo/git -type f -ctime +13 -atime +13 \ | |
| | cut -d'/' -f1-7 | sort | uniq | grep . \ | |
| | xargs -n1 rm -rf | |
| du_after=$(du -hd0 ~/.cargo/ | cut -f1) | |
| if [ "$du_after" != "$du_before" ]; then | |
| # shellcheck disable=SC2088 | |
| echo "~/.cargo: $du_before -> $du_after" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment