find files older than X days in bash and delete
I have a directory with a few TB of files. I'd like to delete every file in it that is older than 14 days.
I thought I would use find . -mtime +13 -delete
. To make sure the command works as expected I ran find . -mtime +13 -exec /bin/ls -lh '{}' \; | grep '<today>'
. The latter should return nothing, since files that were created/modified today should not be found by find
using -mtime +13
. To my surprise, however, find
just spew out a list of all the files modified/created today!
find your/folder -type f -mtime +13 -exec rm {} \;
This works for me.
$ find ./folder_name/* -type f -mtime +13 -print | xargs rm -rf