A faster loop for build-and-test

Developers waste a lot of time manually re-running builds, test suites, and other custom scripts after every edit. While tools like Hugo and Flask include file-watching and auto-rebuild out of the box, most hand-rolled build processes don't. entr fills that gap: it's a command-line utility that watches a set of files and runs any command you specify whenever one of them changes.

You tell entr which files to watch by piping a list to it on stdin:

git ls-files | entr bash my-build-script.sh

Or with a simple ls:

find . -name *.rs | entr cargo test

The pattern is flexible—anything that outputs file paths on stdin works.

Instant feedback with flags for real workflows

The core value is immediate feedback after each change, but entr's flags adapt it to common development scenarios.

Restart a server with -r

If your command starts a long-running process like a development server, pass -r to have entr kill and restart it on each file change:

git ls-files | entr -r python my-server.py

Clear stale output with -c

Build output from previous runs can clutter the terminal and obscure the latest results. The -c flag clears the screen before each re-run, keeping your view focused on the current outcome.

Track new files with -d

A common limitation of file-watching setups is that newly created files aren't always picked up. If you pass -d, entr monitors the directories it's watching and exits when a new file appears. Wrapping the command in a shell loop restarts entr with the updated file list:

while true
do
{ git ls-files; git ls-files . --exclude-standard --others; } | entr -d your-build-script
done

Using entr with Git-tracked files

For most projects, the files you care about are exactly those in version control. Piping git ls-files into entr is a natural fit. To also include untracked files, you can expand the Git command:

git ls-files -cdmo --exclude-standard  | entr your-build-script

A reader suggested wrapping this into a reusable git-entr command that simply runs:

git ls-files -cdmo --exclude-standard | entr -d "$@"

Under the hood: inotify on Linux

On Linux, entr leverages inotify, the kernel's file-system event notification system. A quick strace reveals an inotify_add_watch system call for every file entr is asked to watch:

inotify_add_watch(3, "static/stylesheets/screen.css", IN_ATTRIB|IN_CLOSE_WRITE|IN_CREATE|IN_DELETE_SELF|IN_MOVE_SELF) = 1152

That's all there is to it—a small tool that eliminates a tedious part of the edit-compile-test cycle for any custom build script or long-running service.