Re-run Commands on File Change With watchexec
Watch files and automatically restart a command after edits.
Run watchexec -w src -e rs -- cargo test to rerun tests whenever a Rust file changes.
01Command
Command
$ watchexec -w src -e rs -- cargo test02What it does
watchexec monitors files or directories and restarts the given command on change. Use -w to set watch paths, -e to filter extensions, --debounce to avoid rapid restarts and -c to clear the screen between runs.
03Risk
!Warning: It watches the filesystem continuously and can spin CPU if the watched command itself writes many files.
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- Homebrew formula: watchexecEvidence: Packages watchexec, which watches paths and restarts a command on change.
Last verified: 2026-09-22 · Category: Developer