-
-
Save higgins/b825103ce0bcf3fbefc79a43921244b5 to your computer and use it in GitHub Desktop.
Clean -- remove stale files in commonly dirty directories. "stale" means anything not viewed in over 1 week
This file contains 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
#! /bin/bash | |
# | |
# PURPOSE: | |
# Remove stale files in common directories. "stale" means haven't | |
# viewed in over 1 week. System must write atime | |
# | |
# NOTES: | |
# - check `mount` to confirm atime is set. for my personal machines it | |
# will be. we aint launchin rockets! | |
# | |
# FIXME: | |
# - test it | |
# | |
# TODO: | |
# - parameterize `staleness` | |
# - warn before execution | |
# - report before/after execution | |
# | |
# REFS: | |
# https://unix.stackexchange.com/questions/8840/last-time-file-opened | |
# https://unix.stackexchange.com/questions/9496/looping-through-files-with-spaces-in-the-names | |
# | |
# Disable spotlight indexing | |
# http://osxdaily.com/2011/12/30/exclude-drives-or-folders-from-spotlight-index-mac-os-x/ | |
declare -a LINE_OF_SIGHT=(~/Desktop ~/Downloads ~/Documents) | |
OLD_IFS="$IFS" | |
IFS=$'\n' | |
# iterate through each of our "line of sight" directories (any | |
# directory we want to keep clean) and delete those we haven't | |
# accessed in over a week. Disable indexing of these directories | |
for dirtyDir in "${LINE_OF_SIGHT[@]}" | |
do | |
find $dirtyDir -atime +1w -type f -delete | |
done | |
# Take out the trash | |
rm -rf ~/.Trash/* | |
# If docker is on system, prune unused images | |
if [ -x "$(command -v docker)" ]; then | |
echo "Pruning unused docker images" | |
docker system prune -f | |
fi | |
# teardown | |
IFS="$OLD_IFS" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
comment out the docker prune bits if that's too aggressive for you