if [[ $line == *SECURITYRPT* && (((**If the file is older than 5minutes**))) ]]
then
echo "$line"
else
echo "file present not older than 2minutes"
fi
&&
后列出超过 5 分钟的文件时要设置什么条件?
您可以将find
命令与-mmin
参数一起使用:
本示例查找当前目录(和子目录(中存在时间少于 5 分钟的所有文件。您可以删除"-"以满足您的需求:)
find ./ -type f -mmin -5;
find
手册页
使用touch
创建日期为 5 分钟前的参考文件。
然后测试该文件是否-o
ldert
您的参考文件。
ageref="$(mktemp)"
trap 'rm -f -- "$ageref"' EXIT
if touch -d '-5mn' -- "$ageref" && [[ "$line" == SECURITYRPT && "$file" -ot "$ageref" ]]; then
: # Do watever
fi
请参阅help test | grep -F -- '-ot'
:
FILE1 -ot FILE2
如果文件1早于文件2,则为真。
假设"超过 5 分钟"意味着"在 5 分钟(或更长时间(前修改,在 Linux 中使用 bash :
if (($(date +%s) - $(stat -c %Y "$file") > 300)); then
echo "$file is older that five minutes"
fi
条件(($(date +%s) - $(stat -c %Y "$file") > 300))
,该表达式可用于复合逻辑表达式。