Find – How to Delete Files by Age

findrm

Is there a command to delete all the files in a directory that haven't been modified in N days? I need to clean up some old logs.

Best Answer

This will delete all files older than 5 days, you can put a -name '*log' in there too to be more precise and you might want to specify a maxdepth in the find command too.

find /some/dir -type f -mtime +5 -delete