I have the following peace of code in bash
inotifywait -r -m -e modify -e moved_to -e moved_from -e move -e move_self -e create -e delete -e delete_self $list_of_folders |
while read path action file; do
message=$myip%0A$action%0A$path$file
message
done
I don't know how can I exclude from watch files named "logs.txt" and ".git" folders, can anyone explain how excluding works in inotifywait?
p.s. logs.txt and .git folders, may be in any location, I don't know exactly where
Based on John1024's comment, I believe you need to use --exclude 'logs\.txt|\.git'
in your inotifywait
command like this:
inotifywait --exclude 'logs\.txt|\.git' -r -m -e modify -e moved_to -e moved_from -e move -e move_self -e create -e delete -e delete_self $list_of_folders | # ...
This option takes a regular expression that is used to ignore events whose filename matches it. In this case, the regular expression logs\.txt|\.git
means any filename equal to logs.txt
or (|
) .git
. The backslashes are required to escape the dots because they have a special meaning inside regular expressions.
This exclusion seems to work well for any location of the logs.txt
file or .git
directory. And it even excludes events from descendants of the .git
directory.