Take the 2-minute tour ×

Possible Duplicate:
Deleting files by age

Write a shell script to delete all the files which are "n" of older that current day, where n can be 3days. 2days, or 1 year etc. The above script should only delete files which is having an extension *.log.

Any help on this? Thanks

share|improve this question

marked as duplicate by Gilles, jasonwryan, Renan, uther, Mikel Jan 11 '13 at 4:30


We have plenty of questions already about delete files older. None of them has an answer for your question? –  manatwork Jan 10 '13 at 15:41

1 Answer 1

up vote 3 down vote accepted

just use find command specifing NNN in hours, i.e., 24*number_of_days:

find /path/to/dir -daystart -type f -name \*.log -mtime +NNN -delete
share|improve this answer
Thank you @eppesuig –  user30080 Jan 10 '13 at 15:53
Non-GNU users may need -exec rm -f {} + instead of -delete. –  jordanm Jan 10 '13 at 15:55
@user30080 if you find the answer useful, please click on the up arrow above the answer number. Thanks. –  eppesuig Jan 10 '13 at 16:19
