Automating common tasks with entr(1)

last modified: | 2 min read #linux #tools

As a developer there are many occasions where you are editing some files and executing the same commands over and over again. For example when I’m writing code I like to frequently run my unit tests to make sure that everything still works as expected. I quickly end in the following loop:

$ vim app.py # Making some changes to the source code

$ pytest # Running the tests

$ vim app.py # More changes

$ pytest

This quickly becomes a drag and we might want to run our tests as soon as our source code changes.

Introducing entr(1)

entr is a small tool that allows you to run arbitrary commands as soon as some files change.

Automating the scenario above is as simple as executing the following command

$ find . -type f -path '*.py' | entr pytest

As soon as I save one of my source files entr will make sure my tests are executed.

Other uses

As entr takes it’s input from STDIN you can easily use it for a variety of tasks. The following examples can be found in the man pages:

Launch and auto-reload a node.js server:

$ ls *.js | entr -r node app.js

Clear the screen and run a query after the SQL has been updated:

$ echo my.sql | entr -cp psql /_

Other examples can be found on the website of entr