2011/09/19

Deleting old files with find

There has got to be a way to do this with the built-in -delete option in find. But this is what I used instead to delete files older than 262 days:

find -mtime +262 -exec rm -rf {} +

The mtime option tests for when the file's data was last modified n*24 hours ago. The resulting files end up replacing the {} characters. The + form of the exec options adds each result to the end of the invocation of rm, instead of invoking rm once for each result. I think. It's easier to remember and type than -exec rm -rf {} \;.

See the newer option for finding files newer than the given file. But giving a negative integer argument to mtime may be sufficient.

No comments:

Post a Comment