Since the --exclude
option only acts on filenames, there's no direct way to do it. You could try round-about ways like using find
to print the name of all directories:
inotifywait --exclude "echo -n (;$(find . -maxdepth 1 -mindepth 1 -type d -printf '%P|');echo )" .
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:
find . -maxdepth 1 -mindepth 1 -type d -printf '@%P\n' > list_of_directories
inotifywait --fromfile list_of_directories .
inotifywait
will exclude any files or folders in list_of_directories
which begin with @
(all of them do).
If you're using inotifywait
with the recursive option, let find
list all nested subdirectories as well by removing the -maxdepth
restriction (also applies to the first command):
find . -mindepth 1 -type d -printf '@%P\n' > list_of_directories
inotifywait --fromfile list_of_directories . -r
The -mindepth
is retained to prevent find
from matching .
, and thus excluding the current directory as well.
find
will not catch subdirectories within subdirectories, I just tried it to confirm. I need it to catch all directories and ignore all files. In other words, I just wantinotifywait
to watch changes to files and nothing else. Seemed simple. Oh well. – Sqerstet Nov 03 '14 at 21:53-maxdepth
option to letfind
find all nested subdirectories. – muru Nov 03 '14 at 21:59\n
after@%P
– brian Nov 08 '18 at 17:47inotifywait -mr --exclude '(.chromium)' -e modify -e create -e delete ~/.config
from https://serverfault.com/questions/403874/inotifywait-usage-and-exclude, and it worked. Normally its flooded with junk from Chrome. – alchemy Mar 30 '20 at 22:53foo*/
to expand only to subdirectories and there's no equivalent here - all that pattern gets is the name, and there's no way to tell from the name whether it's a directory). – muru Mar 31 '20 at 02:49