Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find files in created between a date range

Tags:

linux

find

aix

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 created between 01-Aug-13 and 31-Aug-13.

Observations:

  • The touch trick (where you create two empty files to use the -newer option) does not work for me, once the user roles that I have on the server does not allow me to create files.
  • I need to find between specific dates, not days (like: files that were created more than 30 days ago, etc...)
like image 982
sanjuro8998 Avatar asked Aug 20 '13 15:08

sanjuro8998


1 Answers

If you use GNU find, since version 4.3.3 you can do:

find -newerct "1 Aug 2013" ! -newerct "1 Sep 2013" -ls 

It will accept any date string accepted by GNU date -d.

You can change the c in -newerct to any of a, B, c, or m for looking at atime/birth/ctime/mtime.

Another example - list files modified between 17:30 and 22:00 on Nov 6 2017:

find -newermt "2017-11-06 17:30:00" ! -newermt "2017-11-06 22:00:00" -ls 

Full details from man find:

   -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. 
like image 114
codebeard Avatar answered Sep 18 '22 14:09

codebeard