在 linux 中监视文件系统更改的最佳方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8381566/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Best way to monitor file system changes in linux
提问by ReDucTor
I'm looking at building a file system sync utility that monitors file system activity, but it appears that some of the file system monitoring features in the linux kernel are obsolete or not fully featured.
我正在考虑构建一个监视文件系统活动的文件系统同步实用程序,但似乎 linux 内核中的某些文件系统监视功能已过时或功能不全。
What my research as found
我的研究发现了什么
dnotify came first with notification has the features of notifying for delete,modify,access,attribs,create,move can determine file descriptor, however is now out dated by inotify and fanotify
dnotify 首先带有通知,具有通知删除、修改、访问、属性、创建、移动的功能,可以确定文件描述符,但现在已被 inotify 和 fanotify 过时
inotify came out second with notification has the features of notifying access, modify, attrib, close, move, delete, create, etc however it does not give you a file descriptor or process and will be outdated by fanotify
inotify 排在第二位,通知具有通知访问、修改、属性、关闭、移动、删除、创建等功能,但它不会为您提供文件描述符或进程,并且会被 fanotify 过时
fanotify is the latest which informs of access, modify, close, but does not inform of delete or attribs, but does provide file descriptor
fanotify 是最新的,它通知访问、修改、关闭,但不通知删除或属性,但提供文件描述符
I need a way of determining the process (e.g. from fd) and things like delete, modify, attribs, etc in order to sync everything, any suggestions? Unfortunately dnotify seems the best but most out-dated
我需要一种方法来确定过程(例如从 fd)以及删除、修改、属性等,以便同步所有内容,有什么建议吗?不幸的是 dnotify 似乎是最好但最过时的
回答by cnicutar
回答by Henrique M A Costa
There's a good lib providing file descriptors or process with inotify. It has his own C API and the inotifywatch util (good for scripts), all in inotify-tools package.
有一个很好的 lib 提供文件描述符或进程inotify。它有自己的 C API 和 inotifywatch util(适用于脚本),都在 inotify-tools 包中。
- http://www.ibm.com/developerworks/linux/library/l-ubuntu-inotify/index.html
- http://www.infoq.com/articles/inotify-linux-file-system-event-monitoring
- http://www.ibm.com/developerworks/linux/library/l-ubuntu-inotify/index.html
- http://www.infoq.com/articles/inotify-linux-file-system-event-monitoring
I strongly disagree that fanotify will outdate inotify.
我强烈不同意 fanotify 会过时 inotify。
FAM and gamin are very good server/client options. Both of them use inotify as first option over the outdated dnotify and polls. I prefer gamin.
FAM 和 gamin 是非常好的服务器/客户端选项。他们都使用 inotify 作为过时的 dnotify 和 polls 的首选。我更喜欢游戏。
回答by F?rat Kü?üK
incron is a useful tool for the operations like this. You may create a configuration file for the directory or file that you want to watch.
incron 是用于此类操作的有用工具。您可以为要查看的目录或文件创建配置文件。
http://inotify.aiken.cz/?section=incron&page=about&lang=en
http://inotify.aiken.cz/?section=incron&page=about&lang=en
in ubuntu
在 ubuntu
sudo apt-get install incron
/etc/incron.d/mynotification.conf
/etc/incron.d/mynotification.conf
# notification for user creation
/home IN_ALL_EVENTS /opt/notify_user_created.sh $#