Find files between two dates
I’d like to share a simple way I’ve learned to find how many files have been created between two dates, using Linux command line. The method involves find command.
Problem
Working on a project that involved the creation of a lot of KOS objects (nothing difficult, just another DICOM object), I needed a quick and easy way to find out how many files my class method created.
Solution
I knew that find command could help, so I started digging into its manual and at the end I found the right option:
-newerXY file True if the current file has a more recent last access time (X=a), inode creation time (X=B), change time (X=c), or modifica- tion time (X=m) than the last access time (Y=a), inode creation time (Y=B), change time (Y=c), or modification time (Y=m) of file. In addition, if Y=t, then file is instead interpreted as a direct date specification of the form understood by cvs(1). Note that -newermm is equivalent to -newer.
after many trials I ended up with newermt which is newer with sub-options X=m for modification date and Y=t for literal time.
At this point my “command” was taking shape:
find -type f -name "*.dcm" -newermt 2016-04-08 ! -newermt 2016-04-09
Last thing I needed to know, was the number of files that have been created in the desired date interval and this was the easiest part of the command:
wc -l
the command used prints the newline count.
Finally:
find -type f -name "*.dcm" -newermt 2016-04-08 ! -newermt 2016-04-09 | wc -l
Enjoy!