I'm using inotifywait in a script and wondering if there is a way to exclude hidden files from being watched?
I can't seem to determine the regex pattern to exclude hidden files.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
I assume you mean filenames that start with a dot (
.), you can ignore those. The thing with
inotifywait --exclude is that the pattern appears to be matched against the full path of the file, so you'll need to take that into account.
So, if you give
inotifywait the directories
bar to watch, then the patterns match against filenames like
bar/somethingelse. As usual in regexes, you need to escape the dot.
This should watch for all creates in the current directory except for dotfiles (it's a regex, so we need to escape the dots):
inotifywait -ecreate -m --exclude '^\./\.' .
Or, less specifically, exclude dotfiles in any directories, by looking for the combination of a slash and dot:
inotifywait -ecreate -m --exclude '/\.' foo bar
That, of course, will not work if you're watching a directory with a leading dot in some part of the path; it'll match everything in that path.