以下是inotify在Debian上的最佳实践:
sudo apt-get install inotify-tools
安装inotify-tools软件包。inotifywait -m -r -e create,delete,modify /path
持续递归监控目录,指定事件类型。--format
和--timefmt
格式化输出,便于日志记录。/etc/sysctl.conf
,增加fs.inotify.max_user_watches
(如524288)和fs.inotify.max_user_instances
(如1024),并执行sudo sysctl -p
生效。rsync
同步文件。inotifywait
触发自定义脚本,处理特定事件(如配置文件修改后重启服务)。/var/log/inotify.log
),便于审计。fanotify
或第三方工具(如fswatch
)。参考来源:[1,2,3,4,5,6,7,8,9,10]