Last active
September 12, 2018 07:27
-
-
Save vwrs/acbe89dcadf914866f590b8c5ef225cb to your computer and use it in GitHub Desktop.
Delete old files in a folder automatically
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 -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