Tuesday 12 April 2005

Delete files older than X certain days

To delete files older than certain days you use -mtime argument of the find command like this. The following example deletes files which start with the word 'control.' and older than 3 days. That is keeps only the files of the last 3 days and removes the rest.

$ find control.* -mtime +3 -print -exec rm -f {} \;