-
-
Save ShabbirHasan1/fc01e4bc4d335e11db4cb5541387bcfe to your computer and use it in GitHub Desktop.
Deletes ~/.cargo cached data older than 2 weeks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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