I would like to monitor a directory for changes (new files, subdirectories, or changed files or subdirectories). As soon as a change has been detected, I want the passed command to be called. It should continue to monitor for changes and run the command, until the command is killed using ctrl-c.
For example:
$ cd directoryname
$ watchcommand examplecommand arg1 arg2 arg3
...
... change detected in example1.txt, running "examplecommand arg1 arg2 arg3"
...
... change detected in example2.txt, running "examplecommand arg1 arg2 arg3"
I know there are similar questions out there to this question. However, they have not been marked as duplicates of each other, because they all differ in what the user wants to happen once a change has been detected. This question is meant to be more generic. I'm interested in running a placeholder command once changes are detected.
Please post one answer per tool, so that each tool can be voted on separately.
inotifywait
– Raffa Jan 25 '23 at 13:45