【问题标题】:How to find last modified file and it's timestamp no later than today?如何找到最后修改的文件及其时间戳不迟于今天?
【发布时间】:2012-10-29 01:32:35
【问题描述】:

我有一个名为 filename.${date} 的文件列表,例如 foo.20121102,我想使用 bash 工具集打印具有截至今天的时间戳的最后修改文件。

【问题讨论】:

  • 您需要凌晨 00:00 之前的文件吗?还是过去 24 小时内的文件?

标签: perl file bash awk ls


【解决方案1】:

像你问的那样使用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

【讨论】:

    【解决方案2】:
    # 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

    【讨论】:

      猜你喜欢
      • 2017-05-19
      • 2020-06-01
      • 2015-09-06
      • 2023-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-28
      • 1970-01-01
      相关资源
      最近更新 更多