【发布时间】:2012-10-29 01:32:35
【问题描述】:
我有一个名为 filename.${date} 的文件列表,例如 foo.20121102,我想使用 bash 工具集打印具有截至今天的时间戳的最后修改文件。
【问题讨论】:
-
您需要凌晨 00:00 之前的文件吗?还是过去 24 小时内的文件?
我有一个名为 filename.${date} 的文件列表,例如 foo.20121102,我想使用 bash 工具集打印具有截至今天的时间戳的最后修改文件。
【问题讨论】:
像你问的那样使用shell:
for i in *; do
if stat -c %y "$i" | grep -q "^$(date +%Y-%m-%d)"; then
echo "$i has been modified or created today"
else
echo "$i has NOT been modified or created today"
fi
done
【讨论】:
# 24 hours * 60 minutes/hour * 60 seconds/minute
$threshhold = 86400;
$currenttime = time();
if( ($currenttime - $mtime) > $threshhold){
# file was modified within 24 hours
}
对于昨晚午夜之后修改的文件:
if( $mtime > ($currenttime - ($currenttime % 86400)){
# file was modified this calendar day
}
更多信息here
【讨论】: