List of files modified between perticular time period

20,384

Your syntax is slightly off. Let's redo this with meaningful variable names; we'll understand better what's happening as we go along.


export newerthan="2012-10-04 00:05:00"
export olderthan="2012-10-05 16:30:00"
find . -newermt "$newerthan" ! -newermt "$olderthan"

This will first find files and directories modified after October 4th, 2012, at 12:05 AM. Then, it will remove results that were modified after October 5th, 2012, at 4:30 PM.


To get results without the leading ./ on every line, use this command:

find . -newermt "$newerthan" ! -newermt "$olderthan" | sed 's/^.\///g'
Share:
20,384

Related videos on Youtube

Vikram
Author by

Vikram

Updated on September 18, 2022

Comments

  • Vikram
    Vikram over 1 year

    I am trying to get list of files modified between particular period of time as explain in this answer.

    I stored date and time in two variables [nn and nn1 (stupid naming)] and tried with find command. I got following error -

    vikram@vikram-Studio-XPS-1645:~$ echo $nn1
    10-04-12 23:26:48
    vikram@vikram-Studio-XPS-1645:~$ echo $nn
    10-05-12 00:26:48
    vikram@vikram-Studio-XPS-1645:~$ find . -newermt $nn -and -not -newermt $nn1 -print
    find: paths must precede expression: 00:26:48
    Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
    vikram@vikram-Studio-XPS-1645:~$
    

    Why this error occur ??

  • Iluvathar
    Iluvathar almost 8 years
    Why do you need to export your variables if all your use of them is to substitute into a command?