Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

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

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
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.