Find if any files have been recently modified, as quickly as possible

I have a pretty big directory structure with thousands of files. I want to find out if they have changed since a certain time. Now i can use

find <dir> -mmin 30 -type f

.. to find files that have changed in the last 30 minutes. However, this takes a few seconds, and I'm really not interested in (1) finding all the files that have changed, or even (2) finding which files have been changed. I am only looking for a yes / no answer to “any files that have been changed?”.

I can do (1) better using -print -quit to stop after the first file has been found. However, for the case when the files have not changed, the general search still takes a little time.

I was wondering if there is a faster way to test this? Maybe timestamps in a directory? I use ext4 if that matters.

+4
source share
1 answer

For GNU, findyou can use the option -quitto stop the search after the first match.

So, if you want to know if at least one file has been changed in the last 30 minutes, you can run:

find . -mmin -30 -type f -print -quit

This will print the name of the first matching file and close.

, , , , , , .

+1

Source: https://habr.com/ru/post/1621312/


All Articles