はい、inotify でディレクトリを監視できます inotifywait を使用するシステム または inotifywatch inotify ツールから。
inotifywait イベントを検出すると終了します。オプション -r を渡します ディレクトリを再帰的に監視します。例:inotifywait -r mydirectory .
すべてのイベントを監視する代わりに、監視するイベントを指定することもできます。ファイルまたはディレクトリのコンテンツの変更のみを待機するには、オプション -e modify を使用します .
これは、質問で提供された回答の改善です。スクリプトを中断すると、実行プロセスを強制終了する必要があります。
#!/bin/sh
sigint_handler()
{
kill $PID
exit
}
trap sigint_handler SIGINT
while true; do
[email protected] &
PID=$!
inotifywait -e modify -e move -e create -e delete -e attrib -r `pwd`
kill $PID
done