inotify 是 Linux 内核提供的一种文件系统事件监控机制,可以用来监控文件或目录的变化,如创建、删除、修改等。在 Debian 系统中,你可以使用 inotify-tools 包来方便地使用 inotify 功能。
以下是在 Debian 中设置和使用 inotify 的步骤:
sudo apt update inotify-tools:sudo apt install inotify-tools inotifywait 是 inotify-tools 包中的一个命令行工具,用于等待文件系统事件。
inotifywait [选项] 目录 监控单个目录的变化:
inotifywait -m /path/to/directory 这将监控 /path/to/directory 目录,并在检测到任何变化时输出相关信息。
监控多个目录的变化:
inotifywait -m -r /path/to/directory1 /path/to/directory2 这将递归监控 /path/to/directory1 和 /path/to/directory2 目录及其子目录的变化。
监控特定事件:
inotifywait -m -e create,delete,modify /path/to/directory 这将只监控创建、删除和修改事件。
设置超时时间:
inotifywait -t 60 -m /path/to/directory 这将在 60 秒后自动退出监控。
输出详细信息:
inotifywait -m -v /path/to/directory 这将输出更详细的事件信息。
inotifywatch 是另一个 inotify-tools 包中的命令行工具,用于统计文件系统事件。
inotifywatch [选项] 目录 [时间间隔] 监控单个目录的变化并统计事件:
inotifywatch -m -t 60 -e create,delete,modify /path/to/directory 这将监控 /path/to/directory 目录,并在 60 秒后输出事件统计信息。
监控多个目录的变化并统计事件:
inotifywatch -m -r -t 60 -e create,delete,modify /path/to/directory1 /path/to/directory2 这将递归监控 /path/to/directory1 和 /path/to/directory2 目录及其子目录的变化,并在 60 秒后输出事件统计信息。
通过这些工具,你可以在 Debian 系统中方便地设置和使用 inotify 功能来监控文件系统的变化。