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?

  • 1
    Do man find. Boom. – mkoistinen Sep 24 '10 at 19:08
  • 1
    Note to closers: that other question is actually confusingly different, its answers aren't completely straightforward to transpose. – Gilles 'SO- stop being evil' Sep 24 '10 at 21:16
find /the/dir/to/start/in -type f -mtime +365 -ls -exec rm -f -- {} \;
  • 2
    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 'SO- stop being evil' Sep 24 '10 at 21:17
  • 1
    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 'SO- stop being evil' Sep 24 '10 at 21:22
  • This is extremely dangerous as you don't see what you are about to delete and why in the world are you force deleting with -f? Some files are protected for a reason. It's much more safe to store the results of find into a file, then examine them and run rm on contents of the file. – Petr Aug 27 '16 at 10:07

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