Shell Script — Get all files modified after

前端 未结 9 2488
礼貌的吻别
礼貌的吻别 2020-12-12 09:57

I\'d rather not do this in PHP so I\'m hoping a someone decent at shell scripting can help.

I need a script that runs through directory recursively and finds all fil

9条回答
  •  -上瘾入骨i
    2020-12-12 10:28

    If you have GNU find, then there are a legion of relevant options. The only snag is that the interface to them is less than stellar:

    • -mmin n (modification time in minutes)
    • -mtime n (modification time in days)
    • -newer file (modification time newer than modification time of file)
    • -daystart (adjust start time from current time to start of day)
    • Plus alternatives for access time and 'change' or 'create' time.

    The hard part is determining the number of minutes since a time.

    One option worth considering: use touch to create a file with the required modification time stamp; then use find with -newer.

    touch -t 200901031231.43 /tmp/wotsit
    find . -newer /tmp/wotsit -print
    rm -f /tmp/wotsit
    

    This looks for files newer than 2009-01-03T12:31:43. Clearly, in a script, /tmp/wotsit would be a name with the PID or other value to make it unique; and there'd be a trap to ensure it gets removed even if the user interrupts, and so on and so forth.

提交回复
热议问题