5

Assume, I have about 10,000 files in a folder. I have been using hourly crontab to find files that are modified in the last 60 min then process it.

Invoke find -mmin -60 at 01:00:00

Assume 1st file was modified at 00:00:00 and easily found by "find" at 01:00:00.

Then, assume the 10,000th file was modified at 00:00:00 as well

but now is at 01:10:00 and "find" is still working hard to reach the 10,000th file

So now, at 70min later, will "find" return the 10,000th file that was modified at 00:00:00?

3

In GNU find, the reference time which is used to evaluate files with -mmin etc. is calculated and stored when the expression is parsed, so in effect when find starts.

This means that all such time comparisons use the same time reference for all evaluated files, the time at which find parsed its command line.

2

Assuming GNU find, this is easily tested:

% mkdir foo; cd foo; touch a b
% find -mmin 1
.
./a
./b
% find -mmin 1 -exec sleep 120 \; -print 
.     # 2 minutes wait before this showed up
./a   # another 2 minutes before this showed up
./b   # and another 2 minutes for this one
% find -mmin 1
%

So even though b was last modified at least 4 minutes after find ran sleep 120 for a, it still matched.


Since -mmin isn't POSIX, this is up to the implementation, but I'd expect the behaviour seen above.

  • 1
    FWIW, the (FreeBSD-based?) find on my Mac also shows both files with find . -mmin 1 -exec sleep 120 \; -print – ilkkachu Jul 17 at 17:31
0

Try the following command one after another in two terminals

Terminal 1:

find /path -mmin -0.017 -printf "$(date) %Tc %p\n" | grep '/path/to/some/file' 

Terminal 2:

touch -d " 0 seconds ago" /path/to/some/file

we are able to get the result as

Wed Jul 17 11:48:33 IST 2019 Wed 17 Jul 2019 11:48:34 AM IST /path/to/some/file

I'm prefixing the start time of command with find result. it shows, find is able to search for the files which are modified after the start time of the command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.