Removing all files older than X days
I know it’s easy, but every time I write it I have to study the man page of find to figure out the correct parameters:
File only deletion:
find <dir> -atime +7 -type f -print | xargs rm -f
Recursive deletion (be careful):
find <dir> -atime +7 -print | xargs rm -rf
March 20th, 2008 at 12:00 am
I usualy use -mtime instead -atime
March 24th, 2008 at 11:46 pm
I prefer to use -exec instead, as if find returns an extremely large amount of data, you will run into limitations with xargs.
find -atime +7 -type f -exec rm -f {} ;