【问题标题】:how can I find all the file which created after some time, in a given directory?如何在给定目录中找到一段时间后创建的所有文件?
【发布时间】:2013-09-11 13:49:42
【问题描述】:

我用谷歌搜索了find doc,然后写了这篇

find . -type f -depth 1 -Btime 1

但是,我不工作?我怎样才能做到这一点?

【问题讨论】:

    标签: macos shell find


    【解决方案1】:

    您的帖子类似于this thread。无论如何,你可以有这样的命令。

    find -newerct 'now -1 hour'
    

    或者

    BEFORE=$(( $(date '+%s') - 3600 )) ## In seconds = 1 hour.
    find -type f -printf '%C@ %p\n' | while read -r TS FILE; do TS=${TS%.*}; [[ TS -ge BEFORE ]] && echo "$FILE"; done
    

    如果你打算从修改时间开始,你可以有这个

    find -newermt '-1 hour'
    

    或者

    BEFORE=$(( $(date '+%s') - 3600 )) ## In seconds = 1 hour.
    find -type f -printf '%T@ %p\n' | while read -r TS FILE; do TS=${TS%.*}; [[ TS -ge BEFORE ]] && echo "$FILE"; done
    

    【讨论】:

    • 感谢您的快速回复,您使用哪种外壳? '-newerct' 是做什么的?我在文档中找不到这个选项
    • -newerct是inode更改时间(如-ctime);不是创建时间(如-newerbt-Btime)。 OS X 的find 不支持-printf,但您可以使用brew install findutils 安装GNU find
    【解决方案2】:

    -Btime 5 匹配五天前创建的文件(其中 4.1 向上舍入为 5,5.1 向上舍入为 6)。如果您指的是从现在到五天前创建的文件,请使用 -Btime -5

    find . -type f -Btime -5 # five days ago or newer
    find . -type f -Btime 5 # five days ago
    find . -type f -Btime +5 # five days ago or older
    find . -type f -Btime +5 -Btime -10 # between five days ago and ten days ago
    

    还有-maxdepth 1-mindepth 1 -maxdepth 1-depth 1 快。 -depth 1 遍历目录树下的所有文件。

    -atime-Btime-ctime-mtime 可以使用的格式在-atime 下进行了描述:

    -atime n[smhdw]
            If no units are specified, this primary evaluates to true if the difference
            between the file last access time and the time find was started, rounded up to
            the next full 24-hour period, is n 24-hour periods.
    
            If units are specified, this primary evaluates to true if the difference between
            the file last access time and the time find was started is exactly n units.  Pos-
            sible time units are as follows:
    
            s       second
            m       minute (60 seconds)
            h       hour (60 minutes)
            d       day (24 hours)
            w       week (7 days)
    
            Any number of units may be combined in one -atime argument, for example, ``-atime
            -1h30m''.  Units are probably only useful when used in conjunction with the + or
            - modifier.
    

    【讨论】:

      【解决方案3】:
      find . -type f -depth 1 -Btime -1
      

      和“-”到定义的数量

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-02-12
        • 2011-04-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多