How to delete files older than -x- days


I struggled to figure out how to quickly delete files in a directory older than -x- days, but finally found the trick. Below is how I did it:

# find . -mtime +5 -maxdepth 1 -exec rm -rf {} \;

The -maxdepth option tells it not to do recursion, as deleting the directory would get rid of the file anyway. If you don’t want to do a rm -rf, just remove -rf and directories won’t be deleted.

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word