How to list files that were changed in a certain range of time?
Using Gilles' solution and after reading the man find(1) again I found a more simple solution. The best option is the -newerXY. The m and t flags can be used.
m The modification time of the file reference
t reference is interpreted directly as a time
So the solution is
find . -type f -newermt 20111222 \! -newermt 20111225
The lower bound in inclusive, and upper bound is exclusive, so I added 1 day to it! And it is recursive. It works well on find v4.5.9.
Generally speaking, when you're looking for files in a directory and its subdirectories recursively, use find
.
The easiest way to specify a date range with find
is to create files at the boundaries of the range and use the -newer
predicate.
touch -t 201112220000 start
touch -t 201112240000 stop
find . -newer start \! -newer stop
In addition to the answers already given, note that you can directly specify your dates:
find -type f -newermt "2011-12-22" \! -newermt "2011-12-24"
or
find -type f -newermt "2011-12-22 00:00:00" \! -newermt "2011-12-24 13:23:00"
if you additionally want to specify the time.