本文介绍了如何删除文件超过X小时之前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在写需要删除旧文件bash脚本。
I'm writing a bash script that needs to delete old files.
它使用目前实现的:
find $LOCATION -name $REQUIRED_FILES -type f -mtime +1 -delete
这将删除超过1天较旧的文件。
This will delete of the files older than 1 day.
但是,如果我需要一个更精细的分辨率1天,说喜欢6小时老了吗?有没有干净的方式做到这一点,像有使用查找和-mtime是什么?
However, what if I need a finer resolution that 1 day, say like 6 hours old? Is there a nice clean way to do it, like there is using find and -mtime?
推荐答案
请问您有 -mmin
选项?这可以让你测试自去年修改分钟数:
Does your find
have the -mmin
option? That can let you test the number of mins since last modification:
find $LOCATION -name $REQUIRED_FILES -type f -mmin +360 -delete
也许看看使用做同样的工作。 phjr还建议中的注释。
Or maybe look at using tmpwatch
to do the same job. phjr also recommended tmpreaper
in the comments.
这篇关于如何删除文件超过X小时之前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!