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
or in cfengine:
sdserver01.Hr14.Min00_05::
/path/to/the/directory pattern=* age=60 inform=false recurse=2
![]()
