General
cancel
Showing results for 
Search instead for 
Did you mean: 

Does "find" support filtering files by absolute, not relative date/time

SOLVED
Go to solution
Vitaly Karasik_1
Honored Contributor

Does "find" support filtering files by absolute, not relative date/time

Find has many options for filtering files based on "relative" timestamp - i.e., modified 5 days ago.
But is there some option/trick for filtering files modified Feb, 22, for example?
(yes, I know, there are millions ways to do this with another utilities/scripts, but I'm very curious about find ...)
3 REPLIES
Matti_Kurkela
Honored Contributor
Solution

Re: Does "find" support filtering files by absolute, not relative date/time

The portable way would be use the "touch" command with date/time options to create the necessary reference file, and then use find's -newer option with the reference file.

However, Linux has GNU find, which offers more options than POSIX standards requre.

To find files modified on Feb 22, you should think of it as "newer than Feb 22 00:00:00 but not newer than Feb 23 00:00:00".

The command line example for (a recent enough version of) GNU find:

find -newermt 2009-02-22 \! -newermt 2009-02-23

The date/time format may depend on your locale: as the man page says, if "date -d" accepts time specified in a certain format, find will understand it too.

MK
MK
Vitaly Karasik_1
Honored Contributor

Re: Does "find" support filtering files by absolute, not relative date/time

cool!
I wasn't aware about "newermt" and similar options because my RHEL5's find (4.2.27) doesn't have them.

Trick with two "reference" files is very interesting too.

Thanks a lot!
Vitaly
Vitaly Karasik_1
Honored Contributor

Re: Does "find" support filtering files by absolute, not relative date/time

thanks!