Search code examples
linuxopensusegnome-terminalsetuid

Find files created 30 minutes before AND after a given file in Linux


I need to do find files by using the creation time of another file. For example if i create a file at 21:00 with a particular date and later i wanted to find all the files created within 30 minutes after it or.

As i'm a newbie i'm pretty much confused with find. Any help would be appreciated!


Solution

  • You could use find with the option --newerXY

    This allows you to use a file or date as reference for time period start or end.

    For example

    find . -newermt "2014-11-09 12:00:00" ! -newermt "2014-11-09 12:30:00"
    

    Will find all files modified between 12:00:00 and 12:30:00

    Of course you can also provide a file as reference for start or end

    find . -newer somefile ! -newermt "2014-11-09 12:30:00"
    

    Here is the part of the manpage that covers newerXY

    -newerXY reference
    Compares  the  timestamp of the current file with reference.  The reference argument is normally the name of a file (and one of its timestamps is used for the comparison) but it
    may also be a string describing an absolute time.  X and Y are placeholders for other letters, and these letters select which time belonging to how reference  is  used  for  the
    comparison.
    
    a   The access time of the file reference
    B   The birth time of the file reference
    c   The inode status change time of reference
    m   The modification time of the file reference
    t   reference is interpreted directly as a time
    
    Some  combinations  are  invalid; for example, it is invalid for X to be t.  Some combinations are not implemented on all systems; for example B is not supported on all systems.
    If an invalid or unsupported combination of XY is specified, a fatal error results.  Time specifications are interpreted as for the argument to the -d option of  GNU  date.   If
    you  try to use the birth time of a reference file, and the birth time cannot be determined, a fatal error message results.  If you specify a test which refers to the birth time
    of files being examined, this test will fail for any files where the birth time is unknown.