Hello, Sorry for the noob question could not find an answer for this. I need a shell script that I can run in cron that will search one or more folders for specified file(s) and delete them if they are older then (ex: ) 10 days. Thank you
Look up the documentation for find: Code: man find You can for example search for files that were accessed (read) 10 days ago or more with: Code: find . -name '*tmp*' -atime +9 (Note that it's 9 not 10!) With Code: find . -name '*tmp*' -atime +9 -delete You delete them. You can just put that line directly into the cron or in a shell script if you have to. Note: "." is the current working directory. If you want to change it do so ;-).
geek.de.nz, Thank you for the info, never knew you could put something like this right in the cron! I'm guessing I would have to put the complete path since I don't know what the current working directory would be for cron (if i put this right inside the cron). You've got me curious now can you actually run scripts inside cron? Are there any limitations to this?
Ok when i enter this line; find . -name '*.tar.gz' -atime +9 -delete I get this error: find: invalid predicate `-delete'
Have a look at Code: man find To create a cron job that runs your tasl at 05:00h each day (for example), run Code: crontab -e (as root) and enter this: Code: 0 5 * * * find . -name '*tmp*' -atime +9 -delete Instead of just find you can use the full path to find, e.g. /usr/bin/find. Run Code: which find to find out where find is on your system.