A microscopic file watch for Linux.
mfw watches a file for updates, and runs a command when one is detected.
This can be considered a minimal version of inotifywait. See LIMITATIONS.
# Run pdflatex on file change
mfw homework.tex pdflatex homework.texIf the file disappears, the mfw process disappears as well.
Build and install to the default $PREFIX.
make
sudo make installIf $PREFIX is unset, mfw installs to /usr/local.
You can also specify a prefix via environment variable:
# installs to ~/.local/bin/mfw
PREFIX=~/.local make install- Watch for file change to run a shell command
- Kill process if file disappears
- Recursively watch a directory
This only watches a single file using the Linux kernel inotify library.
By using inotify, we inherit some limitations of inotify:
- Nonrecursive (to implement recursion, all of a directory's
subdirectories need manual assignment of
inotifydescriptors) - Requires support by the Linux kernel (reasonable;
inotifywas added in 2.6.13) - May lose events due to race conditions, e.g. time-to-check-to-time-to-use (article)
- Has a maximum amount of simultaneous watches dictated by the kernel (see SUSE docs)
However, since mfw does not implement recursion (not included in inotify API),
the issue of
Note
Although inotify isn't very efficient, alternatives such as fanotify require root.
- swomf/mfw
- 🟩 Implemented in a single source file in pure C.
- 🟩 Minimal memory for the job (uses about 1MB)
- 🟥 Only watches a single file in Linux via
inotify.
- emcrisostomo/fswatch
- 🟩 Written with minimal dependencies in C++11.
- 🟩 Avoids
inotify. - 🟩 Reasonably memory-efficient (starts at around 5MB; uses 42MB to watch my whole home directory)
- Uses autoconf
- watchexec
- 🟩 Written in Rust as both a library and a CLI (
cargo install watchexec-cli) - 🟩 Avoids
inotify - Somewhat memory-efficient (starts at around 10MB; uses 42MB to watch my whole home directory)
- 🟩 Written in Rust as both a library and a CLI (
- inotify-tools: inotifywait
- 🟥 Not as simple as the above three software
- 🟥 Uses
inotifyfor recursion - Uses autoconf
- inotify_dtree.c
- 🟩 Implemented as a single (big) source file in pure C
- 🟥 Written only as a literature example for
inotify - 🟥 Incredibly memory-inefficient during recursion (uses 300MB+ to watch my whole home directory)