Roman Byshko
Roman Byshko

Reputation: 9012

find, rounding and daystart

Suppose a file is created as follows:

$ touch -d "00:00:00 today" stamp

Why the following command does not find it?

$ find -type f -daystart -mtime 0

The following command does find this file

$ find -type f -daystart -mtime -1

Upvotes: 3

Views: 3059

Answers (3)

montjoy
montjoy

Reputation: 363

From my own experimentation it looks like Joakim is right - at least for mmin. daystart seems to be relative from the start of tomorrow.

ls -l stamp*
-rw-r--r-- 1 me me 0 Jun  7 00:01 stamp
-rw-r--r-- 1 me me 0 Jun  7 16:38 stamp2
-rw-r--r-- 1 me me 0 Jun  7 16:55 stamp3

Notice how stamp3 is at 16:55

60*16 + 55 = 1015

1440 (one day) - 1015 = 425

find . -type f -daystart -mmin -425
./stamp3

Let's catch stamp2 also

1440 - 60*16 - 38 = 442

find . -type f -daystart -mmin -442
./stamp2
./stamp3

Now if I want to capture files from a range of times I can do something like this:

find . -type f -daystart -mmin -1439 -mmin +425
./stamp2

Upvotes: 1

Tatu Lahtela
Tatu Lahtela

Reputation: 4554

It looks like a bug. If you add a file with a non-zero time, say

$ touch -d "00:00:00.01 today" stamp

It works as you expect.

Upvotes: 1

Joakim Nohlgård
Joakim Nohlgård

Reputation: 1852

It seems like (at least on my machine) find -daystart actually searches relative the start of tomorrow.

I find the file when I run find -daystart -mtime 1 as well as find -daystart -mmin -1441 (60*24=1440) but not find -daystart -mmin -1440. I can actually find it using exact match with 1441 as well, find -daystart -mmin 1441

Upvotes: 0

Related Questions