以下是一些Ubuntu里inotify的实用技巧:
sudo apt-get update
,sudo apt-get install inotify-tools
。inotifywait -m /path/to/directory -e create,delete,modify
,可监控指定目录下的文件创建、删除和修改事件。-r
选项可递归监控子目录,如inotifywait -m -r /path/to/directory -e create,delete,modify
。--timeout
选项设置超时时间(秒),如inotifywait -m --timeout=60 /path/to/directory -e create,delete,modify
。--format
和--timefmt
选项自定义输出格式,如inotifywait -m -r -e create,delete,modify --format '%T %w%f %e' --timefmt '%Y-%m-%d %H:%M:%S'
。