Find files in created between a date range

后端 未结 8 1012
遥遥无期
遥遥无期 2021-01-30 03:57

I use AIX via telnet here at work, and I\'d like to know how to find files in a specific folder between a date range. For example: I want to find all files in folder X that were

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-30 04:36

    Use stat to get the creation time. You can compare the time in the format YYYY-MM-DD HH:MM:SS lexicographically.

    This work on Linux with modification time, creation time is not supported. On AIX, the -c option might not be supported, but you should be able to get the information anyway, using grep if nothing else works.

    #! /bin/bash
    from='2013-08-01 00:00:00.0000000000' # 01-Aug-13
    to='2013-08-31 23:59:59.9999999999'   # 31-Aug-13
    
    for file in * ; do
        modified=$( stat -c%y "$file" )
        if [[ $from < $modified && $modified < $to ]] ; then
            echo "$file"
        fi
    done
    

提交回复
热议问题