Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question

migrated from Sep 24 '10 at 19:09

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

marked as duplicate by Nifle, Sathya, Dennis Williamson, Doug Harris, BinaryMisfit Sep 24 '10 at 21:39

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.

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
find /the/dir/to/start/in -type f -mtime +365 -ls -exec rm -f -- {} \;
share|improve this answer
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

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
share|improve this answer