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.

Is there a command to delete all the files in a directory that haven't been modified in N days? I need to clean up some old logs.

share|improve this question

1 Answer 1

up vote 10 down vote accepted

This will delete all files older than 5 days, you can put a -name '*log' in there too to be more precise and you might want to specify a maxdepth in the find command too.

find /some/dir -type f -mtime +5 -delete

share|improve this answer
Although wise sysadmins do a dry-run with -ls instead of -delete to make sure this won't delete anything they wanted kept. Yes, speaking from experience here. –  Shadur May 5 '12 at 14:21
Speaking from experience, they also check their path. or not, since I once did the / some/dir/ version. :( –  Hennes Jan 13 '13 at 22:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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