find files older than X days in bash and delete

試著忘記壹切 提交于 2019-12-17 06:13:10

问题


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


来源:https://stackoverflow.com/questions/20238183/find-files-older-than-x-days-in-bash-and-delete

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!