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

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”

One Response to “Deleting Files/Directories X Number of Days or Older in Linux”

  1. Nathan says:

    or in cfengine:

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

    ;)

Leave a Reply