ubuntuでディレクトリの変化を監視するにはinotifywait
を使えばOK
インストール
sudo apt install -y inotify-tools
監視
${TARGET_DIRECTORY}を監視し続ける
inotifywait -r -m ${TARGET_DIRECTORY}
オプションの意味
$ inotifywait -h
-r|--recursive Watch directories recursively.
-m|--monitor Keep listening for events forever. Without
this option, inotifywait will exit after one
参考
inotifywaitによるディレクトリの監視とスクリプト実行
Linuxでファイル・ディレクトリ監視を行う『inotify』