I have seen this answer:
You should consider using inotifywait, as an example:
inotifywait -m /path -e create -e moved_to | while read path action file; do echo "The file '$file' appeared in directory '$path' via '$action'" # do something with the file done
The above script watches a directory for creation of files of any type. My question is how to modify the inotifywait
command to report only when a file of a certain type/extension is created (or moved into the directory). For example, it should report when any .xml
file is created.
What I tried:
I have run the inotifywait --help
command, and have read the command line options. It has --exclude <pattern>
and --excludei <pattern>
options to EXCLUDE files of certain types (by using regular expressions), but I need a way to INCLUDE just the files of a certain type/extension.
path
above is probably not the best variable name if you want to play with this first in a shell. If you use it, then you will not be able to use commands and everything since this has basically just overridden the standardPATH
. Hence I recommend using an alternative var name, likefpath
instead. i.e.while read fpath action file
then any standard command usually available from your shell will still be.