我正在编写一个程序来监视文件系统。但是我无法检测到文件何时被删除。我尝试使用 FAN_MARK_ONLYDIR 标志进行监视,希望在删除受监视目录中的文件时 fanotify 引发一些事件,但没有结果。
甚至可以使用 fanotify 来做到这一点?有什么可以帮助我做到这一点?
最佳答案
根据 linuxquestions.org thread fanotify
不检测文件替换或删除或子目录创建、重命名或删除。另见 baach.de discussion ,比较(或提及)inotify、dnotify、fam、Fanotify、tripwire、Python-fuse
和 llfuse
(python) 等文件或目录更改监视器。
inotify
支持 IN_DELETE
和 IN_DELETE_SELF
事件,如果您使用的目录数量有限,而不是整个文件系统,这很实用使用。
编辑 inotify
网页中提到的限制或注意事项如下:
inotify
monitoring of directories is not recursive: to monitor subdirectories under a directory, additional watches must be created. This can take a significant amount time for large directory trees. ... If monitoring an entire directory subtree, and a new subdirectory is created in that tree, be aware that by the time you create a watch for the new subdirectory, new files may already have been created in the subdirectory. Therefore, you may want to scan the contents of the subdirectory immediately after adding the watch.
关于linux - 如何检测文件已被删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20636334/