在 bash 中查找超过 X 天的文件并删除 [英] find files older than X days in bash and delete
问题描述
我有一个包含几 TB 文件的目录.我想删除其中所有超过 14 天的文件.
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.
我想我会使用 find .-mtime +13 -删除
.为了确保命令按预期工作,我运行了 find .-mtime +13 -exec/bin/ls -lh '{}' ;|grep '<今天>'
.后者应该什么都不返回,因为今天创建/修改的文件不应该被 find
使用 -mtime +13
找到.然而,令我惊讶的是,find
只是吐出了今天修改/创建的所有文件的列表!
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 {} ;
这篇关于在 bash 中查找超过 X 天的文件并删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!