Remove files created more than 30 days ago

I wanted to find all the files in a certain directory that were created more than 30 days ago. I started with:

find /path/to/dir -ctime +30

This was finding directories also, so I added -type

find /path/to/dir -ctime +30 -type f

This listed all the files I wanted, so I just passed -exec

find /path/to/dir -ctime +30 -type f -exec rm {} +

The {} in the -exec is replaced with the file names found, so all the files are removed.

Leave A Reply
All content licensed under the Creative Commons License