我如何在bash检查文件是否被创建大于x前段时间多吗? [英] how do I check in bash whether a file was created more than x time ago?
本文介绍了我如何在bash检查文件是否被创建大于x前段时间多吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在linux下的bash来检查文件是否被创建超过X时以前。
假设文件名为的text.txt,时间为2小时。
如果[什么? ]
然后
回声打印旧不够
科幻
解决方案
仅限于修改时间
如果测试`发现的text.txt-mmin + 120`
然后
回声足够老
科幻
或者,在一个行相同的:
#!/斌/庆典
找到的text.txt -mmin + 120 -exec回声够老\\;
您可以使用 -cmin
变更或 -amin
的访问时间。正如有人指出,我不认为你可以跟踪创建时间。
I want to check in linux bash whether a file was created more than x time ago.
let's say the file is called text.txt and the time is 2 hours.
if [ what? ]
then
echo print "old enough"
fi
解决方案
Only for modification time
if test `find "text.txt" -mmin +120`
then
echo old enough
fi
Or, the same in one line:
#!/bin/bash
find text.txt -mmin +120 -exec echo "old enough" \;
You can use -cmin
for change or -amin
for access time. As others pointed I don’t think you can track creation time.
这篇关于我如何在bash检查文件是否被创建大于x前段时间多吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文