Possible Duplicate:
How do I delete files greater than a certain date on linux

How to delete all files in current directory and it`s sub directories older than one year ?

link|improve this question
1  
Do man find. Boom. – mkoistinen Sep 24 '10 at 19:08
Note to closers: that other question is actually confusingly different, its answers aren't completely straightforward to transpose. – Gilles Sep 24 '10 at 21:16
feedback

migrated from stackoverflow.com Sep 24 '10 at 19:09

This question came from our site for professional and enthusiast programmers.

closed as exact duplicate by Nifle, Sathya, Dennis Williamson, Doug Harris, Diago Sep 24 '10 at 21:39

This question covers exactly the same ground as earlier questions on this topic; its answers may be merged with another identical question. See the FAQ for guidance on how to improve it.

2 Answers

find /the/dir/to/start/in -type f -mtime +365 -ls -exec rm -f -- {} \;
link|improve this answer
1  
find /path/to/files -type f -mtime +365 -delete would be easier. – Chris S Sep 24 '10 at 19:38
-delete isn't in my aix find so I'm not accustomed to using it. I'm glad its implemented in other find binaries though. – bot403 Sep 24 '10 at 19:41
find … -exec rm -f {} + will be a little faster (and it's portable except to ancient systems). – Gilles Sep 24 '10 at 21:17
Also, it's a good idea to use -- in case the first file name begins with a - (although you can guarantee it won't happen if the directory passed to find doesn't begin with a -). – Gilles Sep 24 '10 at 21:22
feedback

If you are removing lots of files this is typically a lot faster than "-exec" or piping to "xargs":

find . -type f -mtime +365 | perl -lne unlink
link|improve this answer
feedback