Delete files older than X days

05-04-2021
opschonen.sh Handy for Octopi and cleaning work folders.

Deletes files older than 5 days:
find . -mtime +5 -exec rm {} \;
Sometimes I have to do this to delete old files I uploaded to Octoprint.

From my crontab I call a script every hour to clean up my temporary folder: I throw away all files older than 10 days:
# !/bin/bash
#Delete files from ff folder older than 10 days
find /media/marcel/4TB/ff -mtime +10 -exec rm {} \;


How to use

Place the script in a file opschonen.sh and make it executable with:
chmod +x opschonen.sh
Run the script from inside a terminal window:
./opschonen.sh

Automatic

Put this script in crontab so that it runs automatically periodically:
crontab -e
View 30 more scripts
 
×
×