Doing an inotifywait
to watch a directory, and trying to exclude all subdirectories from being watched while not excluding the files.
inotifywait -r -q --exclude <pattern> dir/
What to put in <pattern>
? Manual for inotifywait
specifies:
--exclude <pattern>
Do not process any events whose filename matches the specified POSIX extended regular expression, case sensitive.
There's no -type
flag like in find
. I've tried (^/)
but that seems to exclude everything.
Help appreciated.
Since the
--exclude
option only acts on filenames, there's no direct way to do it. You could try round-about ways like usingfind
to print the name of all directories:Note that I didn't specify
-r
, since that will cause newly created subdirectories to be watched too.This might break with some special characters.
You could also try:
inotifywait
will exclude any files or folders inlist_of_directories
which begin with@
(all of them do).If you're using
inotifywait
with the recursive option, letfind
list all nested subdirectories as well by removing the-maxdepth
restriction (also applies to the first command):The
-mindepth
is retained to preventfind
from matching.
, and thus excluding the current directory as well.Just use
--exclude '/\..+'
. This ignores all files that start with a dot.(The
.+
part is so that it does not exclude your base folder).inotifywait
only checks subdirectories because of the parameter-r
.Call it without that parameter and it won't watch subdirectories.
Try this way:
Replace the workspace to your directory name.