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

2 Responses to “Removing all files older than X days”

  1. Yannick Says:

    I usualy use -mtime instead -atime

  2. DJ Says:

    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 {} ;

Leave a Reply