Skip to content

Instantly share code, notes, and snippets.

@vwrs
Last active September 12, 2018 07:27
Show Gist options
  • Save vwrs/acbe89dcadf914866f590b8c5ef225cb to your computer and use it in GitHub Desktop.
Save vwrs/acbe89dcadf914866f590b8c5ef225cb to your computer and use it in GitHub Desktop.
Delete old files in a folder automatically
#!/bin/bash -eu
# for crontab
FILEDIR=/path/to/dir
LOGFILE=/var/log/autodel.log
DAYS=200
PROCESSES=4
CHUNK=10
# delete files older than 200 days & parallelize
/usr/bin/find $FILEDIR -daystart -mtime +$DAYS -type f | /usr/bin/xargs -P$PROCESSES -n$CHUNK /bin/rm -f
/bin/echo "`/bin/date --rfc-3339='date'`: deleted files older than $DAYS days" >> $LOGFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment