fswatch is a command-line utility that monitors changes in the file system. It’s particularly handy when you’re working on code or other files and you want to trigger some action whenever a change occurs. For example, you might use fswatch to automatically compile code, sync files, or reload a web page whenever you save a file.
How It Works
You generally specify a directory (or directories) for fswatch to watch. Then, you can define a command that will run every time a change is detected in those directories. fswatch supports multiple file events like create, update, and delete.
Example Usage
Here’s a basic example to give you an idea of how you might use it:
fswatch -o /path/to/watch | xargs -n1 -I{} ./your-command.shfswatch -o /path/to/watch: Tellsfswatchto monitor changes in/path/to/watch.xargs -n1 -I{} ./your-command.sh: Runs./your-command.sheach time a change is detected.
Installation
Installing fswatch might differ depending on your operating system. If you’re on a Mac, it’s as simple as running:
brew install fswatchFor Linux, you might use a package manager like apt:
sudo apt-get install fswatch