Skip to content

Instantly share code, notes, and snippets.

@awade
Created August 8, 2018 17:08
Show Gist options
  • Save awade/ff691f1a74736177e8f4c70d8ba47f25 to your computer and use it in GitHub Desktop.
Save awade/ff691f1a74736177e8f4c70d8ba47f25 to your computer and use it in GitHub Desktop.
Minimalist bash script for cleaning downloads folder on a mac. Logs which were files deleted. Configured for deleting files older than 7 days. Call from crontab to automate. Use at own risk.
#!/bin/bash
#
# Cleans a mac computer directory when called from crontab
#
#Author: Andrew Wade
#Date: 20170125
#Last modified: yyyymmdd
TIMESTAMP=$(date +"%Y%m%d-%H%M%S")
DIR="$HOME/Downloads/"
LOGFILE="$HOME/roombaroo.log"
echo "Cleanup script run $TIMESTAMP on folder $DIR" >>${LOGFILE}
find $DIR* -type f -ctime +7 -print0 | xargs -0 rm -v >> ${LOGFILE}
find $DIR. -empty -type d -delete
echo "------------------ Script finished -----------------" >>${LOGFILE}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment