Main image
8th April
2008
written by Nick Anderson

I have a few of those directories that files tend to pile up in. I don’t need the files but I also don’t take the time to delete them. Pruning these old files is a good thing to keep your used disk space under control as well as your sanity. Find is a great tool to do this, its extremely flexible I recommend you read the man page next time your bored.

find /directory/with/old/files -mtime +120 -exec rm {} \;

Here we use find to find files that are older than 120 days. The “older” here being the key word. So they might actually be older than 120 days but we are using mtime and mtime is the time when the actual contents of a file was last modified.

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google
  • LinkedIn
  • Reddit
  • Slashdot
  • TwitThis

3 Comments

  1. 09/04/2008

    Instead of “-exec rm {} \;” recent versions of find support “-delete”, which does exactly that and it’s faster (because it doesn’t spawn another process for every file). See find’s man page for more :)

  2. 09/04/2008

    Ah thanks for the tip, -delete is much better

  3. [...] some lovely feedback from Sotiris Tsimbonis on my last post Find and delete old files in linux I have a better (faster) [...]

Leave a Reply