Continuous feedback is the cornerstone of efficient software development and systems management. Manually alt-tabbing to a terminal window to re-run test suites, recompile binaries, or restart services every time you save a source code file introduces unnecessary cognitive friction. While large development ecosystems often bundle complex file-watching daemons, Unix environments thrive on simple, composable tools. entr (Event Notify Test Runner) is a lightweight, zero-dependency command-line utility designed to run arbitrary commands whenever specified files change.
Why Choose entr Over Heavyweight Watchers?
Unlike bulky language-specific file watchers that require runtime environments like Node.js or Python, entr is a compact C binary that adheres strictly to Unix design principles:
- Pipeline Composability: Consumes file paths directly from standard input (stdin) via
find,git ls-files, or shell globbing. - Kernel-Level Event Monitoring: Leverages native kernel event notification subsystems (such as
inotifyon Linux andkqueueon BSD/macOS) for zero-latency detection. - Server Restart Capabilities: Includes dedicated process restart flags (
-r) to cleanly manage long-running daemon processes and web servers. - Clear Screen Support: Can automatically clear terminal scrollback buffers between test iterations for distraction-free output.
Installing entr Across Linux Distributions
Because entr is widely packaged in official distribution repositories, installation requires only your standard package manager.
Installing on Ubuntu, Debian, and Linux Mint
sudo apt update
sudo apt install entr
Installing on Arch Linux and Manjaro
sudo pacman -S entr
Installing on Fedora and RHEL / Rocky Linux
sudo dnf install entr
Core Syntax and How entr Works
The standard pattern for using entr pipes a list of file paths into the command, followed by the utility or script you wish to execute:
find . -name "*.py" | entr python3 main.py
Whenever any .py file in the current directory tree is modified and saved, entr immediately re-executes python3 main.py.
Practical Development Recipes with entr
1. Auto-Running Unit Tests with Clean Screen (-c)
To clear the terminal screen before each execution so you only see the latest test report, add the -c flag:
git ls-files | entr -c pytest tests/
2. Automatically Reloading Persistent Web Servers (-r)
When developing web applications or API servers, the process runs indefinitely until restarted. The -r (restart) flag tells entr to send a SIGTERM signal to the running child process and respawn it upon file changes:
ls *.go | entr -r go run main.go
3. Passing the Modified File as an Argument (/)
If you want to operate specifically on the individual file that triggered the change event (for example, compiling Markdown notes into HTML or running a linter), use the slash / placeholder:
find docs/ -name "*.md" | entr -c pandoc / -o output.html
4. Monitoring Directory Structures for Newly Created Files (-d)
By default, entr tracks the file descriptors piped to it on launch. If you create a brand-new file, standard pipelines will not detect it. The -d flag instructs entr to track directory modifications and exit when a new file appears, allowing an outer shell loop to refresh the file list:
while true; do
find src/ -type f | entr -d cargo check
done
Command-Line Options Reference
| Flag | Function and Behaviour |
|---|---|
-c |
Clears the terminal screen before executing the command. |
-r |
Restarts a persistent child process by terminating and respawning it. |
-s |
Executes commands using the system shell (useful for compound pipelines). |
-p |
Postpones execution until the first file modification occurs. |
-d |
Tracks directory modifications to handle file creation and deletion events. |
/ |
Placeholder replaced with the pathname of the first file that changed. |
By pairing entr with standard Linux search tools, you can automate test execution, asset compilation, and server reloads across any project without relying on complex frameworks.