inotifywait 是一个用于监控文件系统事件的实用程序,它是 inotify-tools 软件包的一部分
inotify-tools。在 Debian 系统上,可以使用以下命令安装:sudo apt-get update
sudo apt-get install inotify-tools
inotifywait 命令监控文件或目录。以下是一些基本示例:example.txt 的文件):inotifywait -m -e modify,attrib,close_write,move,create,delete example.txt
my_directory 的目录):inotifywait -m -r -e modify,attrib,close_write,move,create,delete my_directory
inotifywait -m -e create,delete /path/to/directory
inotifywait -m -e modify,attrib,close_write,move,create,delete --format '%T %w%f %e' /path/to/file_or_directory
backup.sh 的脚本:inotifywait -m -e modify,attrib,close_write,move,create,delete --format '%T %w%f %e' /path/to/file_or_directory | while read date file event; do
./backup.sh "$file"
done
这些示例应该可以帮助您开始使用 inotifywait 命令监控文件和目录。您可以根据需要调整选项和参数以满足您的需求。要了解更多关于 inotifywait 的信息,请查阅其手册页(通过运行 man inotifywait)。