Rerun a command whenever a file changes

A poor man's watch mode for anything that doesn't have one.

SNP 124 #316 Filed cmd linux

With entr (a small package, apt install entr):

shell
ls *.py | entr -c python3 main.py

It reruns the command every time one of the listed files changes; -c clears the screen first. Watch a whole tree with find:

shell
find src -name '*.ts' | entr -c npm test

Without entr, inotifywait from inotify-tools in a loop:

shell
while inotifywait -qr -e modify,create,delete src; do npm test; done

And for the "just rerun it every two seconds" case, there's watch -n 2 ls -l.