find: Remove files modified more than 31 days ago

1 · Benjamin Cane · Aug. 18, 2011, 8:31 p.m.
This is one of those things that you will run into eventually and once you know how, it is extremely useful. Example: # find ./ -type f -mtime +31 -exec rm {} ; This will find all of the files older than 31 days, If you want to do files and directories you will need two commands. # find ./ -not -type d -mtime +31 -exec rm {} ; # find ....