Entr is a useful command-line tool that allows you to run arbitrary commands when files change.
For example, if you develop a Go application, you have to restart the go run
command every time you make changes, as Go does not have a "development server".
You can make your life easier by using entr
with the -r
flag to restart the Go server on file changes:
ls *.go | entr -r go run ./
The entr Man Page also contains more examples, e.g.:
Rebuild a project if source files change, limiting output to the first 20 lines:
$ find src/ | entr sh -c 'make | head -n 20'
Installation
On MacOs you can install the tool with Homebrew:
brew install entr