Skip to content

Instantly share code, notes, and snippets.

@alexheretic
Last active April 12, 2024 17:23
Show Gist options
  • Save alexheretic/661cb78b49ca280c629c64be0fabf8d2 to your computer and use it in GitHub Desktop.
Save alexheretic/661cb78b49ca280c629c64be0fabf8d2 to your computer and use it in GitHub Desktop.
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