find files older than X days in bash and delete

2020-01-25 09:28发布

问题:

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!

回答1:

find your/folder -type f -mtime +13 -exec rm {} \;


回答2:

This works for me.

$ find ./folder_name/*  -type f -mtime +13 -print | xargs rm -rf


标签: bash find