Deleting Files/Directories X Number of Days or Older in Linux

March 15, 2007 at 11:37 pm

In order to help keep your servers disk space free, often times you will need to delete files and directories of a certain age or older. You can do this various ways however using the find command can be a very effective technique. Always use caution when doing mass deletes, or you may end up with to much free space…

To find “FILES & DIRECTORIES” 60 days or older

find /path/to/the/directory -mtime +60 -exec ls -la {} \; 

To find and delete “FILES ONLY” 60 days or older

find /path/to/the/directory -mtime +60 -exec rm {} \;

To find and delete “DIRECTORIES & FILES” 60 days or older

find /path/to/the/directory -mtime +60 -exec rm -rf {} \;

*Special Note
mtime = The modication time of the INODE not to be confused with the time you see when doing and “ls”

Category: Systems 101

1 Comment
Gravatar

Comment by Nathan

Made Tuesday, 15 of May , 2007 at 4:07 pm

or in cfengine:

sdserver01.Hr14.Min00_05::
/path/to/the/directory pattern=* age=60 inform=false recurse=2

;)

Leave a comment

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