Delete files older than X days

05-04-2021 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 and make it executable with:
chmod +x
Run the script from inside a terminal window:


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