简体   繁体   English

尽可能快地查找最近更改的文件

[英]Find if any files recently changed, as fast as possible

I have a fairly large directory structure with thousands of files. 我有一个相当大的目录结构,包含数千个文件。 I want to figure out if any have changed since a particular time. 我想知道自特定时间以来是否有任何改变。 Now, I can use 现在,我可以使用

find <dir> -mmin 30 -type f

..to find any files that changed in the last 30 minutes. ..找到过去30分钟内发生变化的文件。 However, this take a few seconds to go through, and I'm really not interested in (1) finding all the files that changed, or even (2) finding which files have changed. 但是,这需要几秒钟才能完成,我真的不感兴趣(1)查找所有更改的文件,甚至(2)查找哪些文件已更改。 I'm only looking for a yes/no answer to "any files changed?". 我只是在寻找“任何文件已更改?”的是/否答案。

I can make (1) better by using -print -quit to stop after the first file was found. 我可以通过使用-print -quit在找到第一个文件后停止来使(1)更好。 However, for the case where no files have changed, the total search still takes a little while. 但是,对于没有文件更改的情况,总搜索仍需要一段时间。

I was wondering if there was a quicker way to check this? 我想知道是否有更快的方法来检查这个? Directory time stamps, maybe? 目录时间戳,也许? I'm using ext4, if it matters. 我正在使用ext4,如果重要的话。

For GNU's find you may use option -quit to stop searching after the first match. 对于GNU的find您可以使用选项-quit在第一场比赛后停止搜索。

So if you want to find out, if there is at least one file changed in the past 30 minutes, then you can run: 因此,如果您想查找,如果在过去30分钟内至少更改了一个文件,那么您可以运行:

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

That will print out name of the first matched file and quit. 这将打印出第一个匹配文件的名称并退出。

Also, if you have control over the software that uses your bunch of files, and performance is not an issue, you may add a feature of touching a timestamp file everytime any file is changed or added and then check only that timestamp file's stats. 此外,如果您可以控制使用一堆文件的软件,并且性能不是问题,那么您可以在每次更改或添加任何文件时添加触摸时间戳文件的功能,然后仅检查该时间戳文件的统计信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM