In the GNU find
man, you can read this about the -atime
option:
-atime n
File was last accessed n*24 hours ago. When find figures out how many 24-hour periods ago the file was last accessed, any fractional part is ignored, so to match -atime +1, a file has to have been accessed at least two days ago.
Note the use of "n*24 hours ago" instead of "n days ago".
Now this is getting me worried about what happens when switching to winter time on that day that is 25 hours long (and there are occasionally days that are 24 hours and 1 second long when there is a leap second).
If I have a daily cron job using find -daystart -atime +1
, is it potentially missing files accessed during that repeated hour?
Best Answer
For
-daystart
the manual says:What that means that if you run:
on the day after the winter changing time (2015-10-25 in Europe this year), that should give you the files last modified between
2015-10-25 01:00
(the first occurrence of that time) and2015-10-25 23:59:59.999...
.If run as
on 2015-10-25, you'd expect it to get you the files modified between 00:00 and 22:59:59, but doing a simple test (with findutils 4.4.2) shows that it returns files modified between the first 01:00 and 23:59:59 (unless run before the time change).
In any case the statement So, to list the regular files in your home directory that were modified yesterday above is not always true.
Without
-daystart
, the check is for files modified in units of 24 hours. So if run at12:43
on 2015-10-25,find . -mtime 0
would give you files modified between 2015-10-24 13:43 and now.A more reliable way to give you the files that were last modified yesterday would be:
Note that it includes the files that were last modified today at 00:00:00.0000000000 and not the ones at that time yesterday. Unfortunately there's no
-oldermt
predicate.Note that
zsh
'sage
function to use in globs like:has similar issues.