1

man inotifywait:

delete_self A watched file or directory was deleted. After this event the file or directory is no longer being watched. Note that this event can occur even if it is not explicitly being listened for.

unmount The filesystem on which a watched file or directory resides was unmounted. After this event the file or directory is no longer being watched. Note that this event can occur even if it is not explicitly being listened to.

How to understand mean of "that this event can occur even if it is not explicitly being listened" on that manual page?

https://manpages.debian.org/stretch/inotify-tools/inotifywait.1.en.html

2 Answers2

3

When you ask inotifywait to wait for an event (i.e. not in --monitor mode), and you specify one or more event types (with the --event option), it normally doesn't exit until that particular event occurs. For example:

$ touch foo
                                    $ inotifywait -e access foo
                                    Setting up watches.
                                    Watches established.
$ echo >>foo

$ cat foo
                                    foo ACCESS 
$                                   $ echo $?
                                    0
                                    $

(The two columns represent separate terminals, with blank lines inserted to make the events come out in chronological order.) Here, after the watch on foo is established, there's a MODIFY event, but since the event filter on the inotifywait doesn't include MODIFY, nothing happens. The inotifywait command only returns later when an ACCESS event happens.

Now suppose the file is deleted while it's being watched for access.

                                    $ inotifywait -e access foo
                                    Setting up watches.
                                    Watches established.
$ rm foo
$                                   $ echo $?
                                    1
                                    $

Removing foo triggers a DELETE_SELF event. The inotifywait command sees this event. It doesn't print it, because it was told to only report ACCESS events. But inotifywait exits: it did count the event even though it wasn't in the filter. The command exits with status 1 to indicate that “an event occurred which was not being listened for” (and wasn't ignored as most non-watched events are).

1

It means you can get these events even if you used the -e option and didn't specify them. For instance, if you use

inotifywait -e modify filename

and the file is deleted, you'll get a delete_self event, even though you only asked for modify events.

This means you need to check the event type in the output, even if you only requested a specific event.

Barmar
  • 9,927
  • Thank you ,but really I need check output ? non-specified event seem is hide on output as Gilles said and I tested that. – illiterate Nov 08 '17 at 05:02
  • If you don't check the output, you have to check the exit status, as he pointed out. – Barmar Nov 08 '17 at 05:35