Skip to content

Instantly share code, notes, and snippets.

@joemaller
Last active November 2, 2023 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joemaller/c4c0a6000ac53c8b1a70ff66c547380a to your computer and use it in GitHub Desktop.
Save joemaller/c4c0a6000ac53c8b1a70ff66c547380a to your computer and use it in GitHub Desktop.
Example cron task for auto-removing old downloads on macOS Big Sur and Catalina
# Cron on modern macOS systems (10.14+) requires Full Disk Access permissions
# in System Preferences->Privacy & Security. To enable this, drag the cron
# binary from /usr/sbin/cron into the Full Disk Access list.
# More here: https://apple.stackexchange.com/a/372810/42898
# https://gist.github.com/joemaller/c4c0a6000ac53c8b1a70ff66c547380a
# Removes downloads older than 14 days. Runs every 6 hours
45 */6 * * * echo "$(date)\nRemoving downloads older than 14 days (cron)" >> /tmp/cron.log
45 */6 * * * find ~/Downloads -maxdepth 1 -mtime +14 -exec du -sh {} \+ | sort -rh >> /tmp/cron.log
46 */6 * * * find ~/Downloads -maxdepth 1 -mtime +14 -exec rm -rf {} \; >> /tmp/cron.log 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment