BASH-删除3个月以上的文件? [英] BASH - Delete files older than 3 months?
本文介绍了BASH-删除3个月以上的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
删除三个月以上的文件如何?
Delete files older than 3 months how?
我知道90天了:
find /tmp/*.log -mtime +90 -type f -delete
但是我怎么知道3个月等于总是90天?多少天?有没有更好的办法告诉 -mtime
遵循 months
?
But how do i know 3 months equal to always 90 days? how many exact days? Is there more better way to tell the -mtime
to follow months
?
推荐答案
如果您想要3个月的确切天数,则可以使用:
If you want exact number of days for 3 months then you can use:
days=$(( ( $(date '+%s') - $(date -d '3 months ago' '+%s') ) / 86400 ))
并将其用作:
find /tmp/*.log -mtime +$days -type f -delete
或直接在查找
中查找:
find /tmp/*.log -type f \
-mtime "+$(( ( $(date '+%s') - $(date -d '3 months ago' '+%s') ) / 86400 ))" -delete
这篇关于BASH-删除3个月以上的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文