【问题标题】:How to listen only to specific events in inotifywait?如何只监听 inotifywait 中的特定事件?
【发布时间】:2018-03-17 02:18:50
【问题描述】:

有人可以解释为什么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,如果这有什么改变的话。

【问题讨论】:

  • --exclude 用于排除匹配的文件名。它与排除特定事件没有任何关系。请参阅 inotifywait 手册页。

标签: linux bash centos inotify inotifywait


【解决方案1】:

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

inotifywait -rme create,modify /tmp/a/

inotifywait(1) - Linux man page

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-21
    • 2020-03-11
    • 2022-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-15
    相关资源
    最近更新 更多