如何只监听inotifywait中的特定事件?

How to listen only to specific events in inotifywait?

有人可以解释为什么 inotifywait 在我排除打开文件后仍然报告打开文件吗?

mkdir /tmp/a

inotifywait --exclude acess,attrib,close_write,close_nowrite,close,open,moved_to,moved_from,move,delete,delete_self,unmount -r -m /tmp/a/

touch /tmp/a/test
/tmp/a/ OPEN test
/tmp/a/ CLOSE_NOWRITE,CLOSE test

我感兴趣的是是否创建了新文件或修改了当前文件。

我使用的是 CentOS 7,如果这有什么变化的话。

-e 事件(仅侦听特定事件)与 --exclude <pattern> 不同,后者意味着不处理文件名与指定正则表达式匹配的任何事件。您的实际命令需要在 events 列表中没有 open 才能观看。例如如果您只对 createmodify 感兴趣,就做

inotifywait -rme create,modify /tmp/a/

inotifywait(1) - Linux man page