How to execute a command whenever a file changes?
while inotifywait -e close_write myfile.py; do ./myfile.py; done or
inotifywait -q -m -e close_write myfile.py | while read -r filename event; do ./myfile.py # or “./$filename” done The first snippet is simpler, but it has a significant downside: it will miss changes performed while inotifywait isn’t running (in particular while myfile is running). The second snippet doesn’t have this defect.
Tags: cli, linux, snipped