Find files in created between a date range

后端 未结 8 994
遥遥无期
遥遥无期 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条回答
  • 2021-01-30 04:30

    List files between 2 dates

    find . -type f -newermt "2019-01-01" ! -newermt "2019-05-01"

    or

    find path -type f -newermt "2019-01-01" ! -newermt "2019-05-01"

    0 讨论(0)
  • 2021-01-30 04:32

    You can use the below to find what you need.

    Find files older than a specific date/time:

    find ~/ -mtime $(echo $(date +%s) - $(date +%s -d"Dec 31, 2009 23:59:59") | bc -l | awk '{print $1 / 86400}' | bc -l)
    

    Or you can find files between two dates. First date more recent, last date, older. You can go down to the second, and you don't have to use mtime. You can use whatever you need.

    find . -mtime $(date +%s -d"Aug 10, 2013 23:59:59") -mtime $(date +%s -d"Aug 1, 2013 23:59:59")
    
    0 讨论(0)
  • 2021-01-30 04:33

    Try this:

    find /var/tmp -mtime +2 -a -mtime -8 -ls

    to find files older than 2 days but not older than 8 days.

    0 讨论(0)
  • 2021-01-30 04:34

    Some good solutions on here. Wanted to share mine as well as it is short and simple.

    I'm using find (GNU findutils) 4.5.11

    $ find search/path/ -newermt 20130801 \! -newermt 20130831
    
    0 讨论(0)
  • 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
    
    0 讨论(0)
  • 2021-01-30 04:42

    Explanation: Use unix command find with -ctime (creation time) flag

    The find utility recursively descends the directory tree for each path listed, evaluating an expression (composed of the 'primaries' and 'operands') in terms of each file in the tree.

    Solution: According to documenation

    -ctime n[smhdw]
                 If no units are specified, this primary evaluates to true if the difference
                 between the time of last change of file status information and the time find
                 was started, rounded up to the next full 24-hour period, is n 24-hour peri-
                 ods.
    
                 If units are specified, this primary evaluates to true if the difference
                 between the time of last change of file status information and the time find
                 was started is exactly n units.  Please refer to the -atime primary descrip-
                 tion for information on supported time units.
    

    Formula: find <path> -ctime +[number][timeMeasurement] -ctime -[number][timeMeasurment]

    Examples:

    1.Find everything that were created after 1 week ago ago and before 2 weeks ago

    find / -ctime +1w -ctime -2w

    2.Find all javascript files (.js) in current directory that were created between 1 day ago to 3 days ago

    find . -name "*\.js" -type f -ctime +1d -ctime -3d

    0 讨论(0)
提交回复
热议问题