entr is a tool I found by chance, and it pleasantly surprised me. It allows you to run commands when files change. I found very few articles about it, so I decided to write this note.
A basic usage example looks like this:
ls nginx.conf | entr nginx -t
When the configuration file changes, entr runs nginx -t again. This is especially useful when editing configuration files, as it allows you to validate them immediately after saving.
Some flags make entr more comfortable to use.
Restart a long-running process (-r)
ls *.py | entr -r python my-server.py
The -r flag restarts the command every time a file changes. This is important for long-running processes like development servers, because without -r the previous process would keep running.
Clear the screen before each run (-c)
ls *.conf | entr -c nginx -t
The -c flag clears the terminal before running the command.
Watching new files (-p)
find . -name '*.conf' | entr -p nginx -t
The -p flag also reacts to newly created files. This is useful when files are added dynamically.
Conclusion
If you often edit files and rerun commands manually, entr is a great tool.
Top comments (1)
Such a useful automation tool, thx