entr
Run commands when files change
TLDR
Rebuild with make if any file in any subdirectory changes
Rebuild and test with make if any .c source files in the current directory change
Send a SIGTERM to any previously spawned ruby subprocesses before executing ruby main.rb
Run a command with the changed file (/_) as an argument
[c]lear the screen and run a query after the SQL script is updated
Rebuild the project if source files change, limiting output to the first few lines
Launch and auto-[r]eload a Node.js server
SYNOPSIS
entr [options] command [arguments]
PARAMETERS
-a
Act immediately when entr starts, before any file modifications. Useful when you need immediate actions
-c
Clear the screen before executing the command.
-d
Debug mode. Prints verbose information about file events.
-n
Limit the number of times the command will execute.
-p
Behave like 'touch' and update the modification time of the input files. Useful for triggering actions based on modification times.
-r
Reload the command if entr is terminated by a signal. Useful for daemons and long-running processes.
-s
Use the shell to execute the command given by arguments
-t
Use the current terminal to execute the command
-z
Null-terminate the file list passed to the command.
-w
Wait for all commands to complete before continuing.
-N
Show notifications to the user if a file is changed
-v
Display entr version and exit
DESCRIPTION
entr is a utility that executes an arbitrary command when files in a specified directory tree are modified. It takes a list of filenames as input, either via standard input or as command line arguments, and monitors those files for changes. When a change is detected (modification, creation, deletion), entr executes the command given as arguments to entr itself. This is useful for automatically running tests, rebuilding software, or performing other actions when source files are modified. It significantly simplifies the process of continuous testing and development by eliminating the need for manual intervention after each code change.
entr offers flexibility in how changes are detected and how the command is executed. It can detect various types of changes and provides options to control the command's environment and signal handling. It helps to speed up workflows and improve efficiency by immediately reacting to file changes.
CAVEATS
entr relies on inotify (or similar kernel mechanisms) for file change detection. There are limits to the number of files that can be monitored. Exceeding these limits will cause errors. It can also be problematic when working with network filesystems due to latency.
USAGE EXAMPLES
- Run tests whenever source files change:
find . -name '*.c' | entr make test
- Automatically rebuild a project:
find . -name '*.cpp' -o -name '*.h' | entr make
- Execute a command every time a file is modified:
ls *.txt | entr echo "File changed!"
SEE ALSO
inotifywait(1), watch(1), find(1)