inotifywait - exclude regex pattern formatting

gsklee picture gsklee · Oct 30, 2011 · Viewed 14.9k times · Source

I am trying to use inotifywait to watch all .js files under my ~/js directory; how do I format my regex inside the following command?

$ inotifywait -m -r --exclude [REGEX HERE] ~/js

The regex - according to the man page, should be of POSIX extended regular expression - needs to match "all files except those that ends in .js", so these files can in turn be excluded by the --exclude option.

I've tried the (?!) lookaround thing, but it doesn't seem to work in this case. Any ideas or workarounds? Would much appreciate your help on this issue.

Answer

FailedDev picture FailedDev · Oct 30, 2011

I've tried the (?!) thing

This thing is called negative lookahead and it is not supported by POSIX ERE.

So you have to do it the hard way, i.e. match everything that you want to exclude.

e.g.

\.(txt|xml) etc.