【问题标题】:inotifywait command not detecting files but folders it doesinotifywait 命令不检测文件,但它检测文件夹
【发布时间】:2009-07-16 10:08:18
【问题描述】:

我尝试使用 inotifywait 来检测每次文件或文件夹被实时移动到文件夹中(例如 /root)

我试过这个,它确实检测文件夹和文件,但这是一个创建的文件,我希望它用于移动的文件/文件夹。

inotifywait --monitor --format %f --event create /root

然后我使用它,但是使用它只会看到何时移入文件夹,当我移入文件时什么都没有显示... :(

inotifywait --monitor --format %f --event moved_to /root

知道发生了什么吗?

PS,我使用的是 Linux,Debian 5 (Lenny)。

【问题讨论】:

    标签: linux bash shell


    【解决方案1】:

    您可以使用 inotify 指定许多事件。在你的情况下,你似乎需要类似的东西:

    inotifywait --monitor --format %f --event move --event create /root
    

    它应该可以工作。如果您需要更多,请仔细阅读手册页:

      -e <event>, --event <event>
            Listen for specific event(s) only. 
            The events which can be listened for are listed in the EVENTS section.
            This option can be specified more than once.  
            If omitted, all events are listened for.
    
    [...]
    
    EVENTS
           The following events are valid for use with the -e option:
    
    [...]
           move   A  file  or  directory  was moved from or to a watched directory.  
           Note that this is actually implemented simply by listening for both moved_to
           and moved_from, hence all close events received will be output as one or both
           of these, not MOVE.
    
           create A file or directory was created within a watched directory.
    

    它适用于我的移动/触摸。希望对您有所帮助...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-15
      • 2018-06-27
      • 2018-12-11
      • 2019-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多