简体   繁体   English

如何检测子目录中的某个文件是否已更改?

[英]How can I detect if some file in a subdir changed?

Basically I have a big directory (>10GB)(each subdir only has a few other subdirs) and want to do sth to any files that changes. 基本上我有一个大目录(> 10GB)(每个子目录只有几个其他子目录),并希望对任何更改的文件做某事。 I can't just go through all the files and check, because it takes to long and uses about 90% of my CPU :(. 我不能只是浏览所有文件并检查,因为它需要很长时间并占用我CPU的90%左右:(。

This is how it looks basically: 这基本上是这样的:

dir
dir/subA
dir/subA/subAsubA
dir/subA/subAsubB
...
dir/subB
dir/subB/subBsubA
dir/subB/subBsubB
...
dir/SubC
dir/SubD
...

My thought was like this(file "test" in subBsubA chaged): 我的想法是这样的(subBsubA chaged中的文件“test”):

Check dir
 -> dir changed
   -->Check subA
      -> subA didn't change
   -->Check subB
      -> subB changed
      --> Check subBsubA
          -> subBsubA changed
             --> Check all files

But sadly the change of a file only effects the modification date of the direct parent directory :( 但遗憾的是,文件的更改只会影响直接父目录的修改日期:(

As @Aereaux pointed out you probably need inotify , available in Linux since 2.6.13. 正如@Aereaux指出的那样,你可能需要inotify ,自2.6.13以来在Linux中可用。 See http://en.wikipedia.org/wiki/Inotify http://en.wikipedia.org/wiki/Inotify

There are inotify-tools available for command line usage as well. 还有inotify-tools可用于命令行使用。 http://techarena51.com/index.php/inotify-tools-example/ http://techarena51.com/index.php/inotify-tools-example/

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

相关问题 如何在Linux中检测文件访问? - How can I detect file accesses in Linux? 如何在SSH下的Powershell中启动某些文件管理器? - How can i start some file manager in Powershell under SSH? 如何计算程序文件中的行数(多个),过滤一些文件和一些行? - How can I count lines in my program files (multiple), filtering some file and some lines? 我如何基于文件2中的一些数字范围使awk将文件1中的行与文件2中的行进行匹配 - how can I make awk match up lines in file 1 with the lines in file 2 based on some number ranges in file 2 如何使某些文件对进程可见,以及当某些进程访问该文件然后提供某些Internet流的内容时? - How can I make some file visible for processes and when some process access it then feed content of some internet stream? 如何在Go中检测操作系统版本? - How Can I Detect the OS Version in Go? 如果我不知道确切的文件路径,Perl如何检测文件? - How can Perl detect a file if I don't know the exact filepath? 如何在Linux上检测慢速文件系统? - How can I detect slow filesystems on Linux? 如何在 Linux 上检测 CDRom 是否是 DVD - How can I detect if CDRom is a DVD on Linux 如何使用%F bash shell从文件内容中检测日期 - How can I detect a date from the content of a file using %F bash shell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM