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

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

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 4
    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

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
  • 1
    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

Not the answer you're looking for? Browse other questions tagged or ask your own question.