inotifywait命令不检测文件,但检测文件夹

时间:2021-05-18 01:07:01

Im trying to use inotifywait to detect every time a file or folder gets moved into a folder in realtime (eg. /root in the case)

我试图使用inotifywait来检测每次文件或文件夹实时移动到文件夹中(例如,/ root中的情况)

I tried this, which does detect both folders and files, but this is for a created file, I want it for a moved file/folder.

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

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

So then I use this, but using this only sees when a folder is moved in, when I move in a file nothing is shown... :(

所以然后我使用它,但使用它只看到文件夹移入时,当我移动文件时没有显示任何... :(

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

Any idea what's going on?

知道发生了什么事吗?

PS, Im using Linux, Debian 5 (Lenny).

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

1 个解决方案

#1


You can specify many events with inotify. In your case it seems you need something like :

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

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

It should works. If you need more, read carefully the man page :

它应该有效。如果您需要更多内容,请仔细阅读手册页:

  -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.

It works for me with move / touch. Hope it helps ...

它适用于移动/触摸。希望能帮助到你 ...

#1


You can specify many events with inotify. In your case it seems you need something like :

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

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

It should works. If you need more, read carefully the man page :

它应该有效。如果您需要更多内容,请仔细阅读手册页:

  -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.

It works for me with move / touch. Hope it helps ...

它适用于移动/触摸。希望能帮助到你 ...