Find files in created between a date range

后端 未结 8 997
遥遥无期
遥遥无期 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:49

    Script oldfiles

    I've tried to answer this question in a more complete way, and I ended up creating a complete script with options to help you understand the find command.

    The script oldfiles is in this repository

    To "create" a new find command you run it with the option -n (dry-run), and it will print to you the correct find command you need to use.

    Of course, if you omit the -n it will just run, no need to retype the find command.

    Usage:

    $ oldfiles [-v...] ([-h|-V|-n] | {[(-a|-u) | (-m|-t) | -c] (-i | -d | -o| -y | -g) N (-\> | -\< | -\=) [-p "pat"]})

    • Where the options are classified in the following groups:
      • Help & Info:

        -h, --help : Show this help.
        -V, --version : Show version.
        -v, --verbose : Turn verbose mode on (cumulative).
        -n, --dry-run : Do not run, just explain how to create a "find" command

      • Time type (access/use, modification time or changed status):

        -a or -u : access (use) time
        -m or -t : modification time (default)
        -c : inode status change

      • Time range (where N is a positive integer):

        -i N : minutes (default, with N equal 1 min)
        -d N : days
        -o N : months
        -y N : years
        -g N : N is a DATE (example: "2017-07-06 22:17:15")

      • Tests:

        -p "pat" : optional pattern to match (example: -p "*.c" to find c files) (default -p "*")
        -\> : file is newer than given range, ie, time modified after it.
        -\< : file is older than given range, ie, time is from before it. (default)
        -\= : file that is exactly N (min, day, month, year) old.

    Example:

    • Find C source files newer than 10 minutes (access time) (with verbosity 3):

    $ oldfiles -a -i 10 -p"*.c" -\> -nvvv Starting oldfiles script, by beco, version 20170706.202054... $ oldfiles -vvv -a -i 10 -p "*.c" -\> -n Looking for "*.c" files with (a)ccess time newer than 10 minute(s) find . -name "*.c" -type f -amin -10 -exec ls -ltu --time-style=long-iso {} + Dry-run

    • Find H header files older than a month (modification time) (verbosity 2):

    $ oldfiles -m -o 1 -p"*.h" -\< -nvv Starting oldfiles script, by beco, version 20170706.202054... $ oldfiles -vv -m -o 1 -p "*.h" -\< -n find . -name "*.h" -type f -mtime +30 -exec ls -lt --time-style=long-iso {} + Dry-run

    • Find all (*) files within a single day (Dec, 1, 2016; no verbosity, dry-run):

    $ oldfiles -mng "2016-12-01" -\= find . -name "*" -type f -newermt "2016-11-30 23:59:59" ! -newermt "2016-12-01 23:59:59" -exec ls -lt --time-style=long-iso {} +

    Of course, removing the -n the program will run the find command itself and save you the trouble.

    I hope this helps everyone finally learn this {a,c,t}{time,min} options.

    the LS output:

    You will also notice that the "ls" option ls OPT changes to match the type of time you choose.

    Link for clone/download of the oldfiles script:

    https://github.com/drbeco/oldfiles

提交回复
热议问题