Search code examples
linuxbashcentosinotifyinotifywait

How to listen only to specific events in inotifywait?


Can someone explain why inotifywait still reports about opened files, when I have excluded open?

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

All I am interested in is if new files are made or current files are modified.

I use CentOS 7, if that changes anything.


Solution

  • The -e event (Listen for specific event(s) only) is different from the --exclude <pattern> which is meant for not processing any events whose filename matches the specified regular expression. Your actual command needed to be without open on the list of events to watch on. For e.g. if you are interested in only create and modify just do

    inotifywait -rme create,modify /tmp/a/
    

    inotifywait(1) - Linux man page