Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

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

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