fswatch
fswatch 是一个使用 Mac OS X FSEvents API 监控目录的小程序。
当收到有关对该目录的任何更改的事件时,指定的
shell命令由/bin/bash执行
如果您使用的是 GNU/Linux,
inotifywatch(部分
inotify-tools 包在大多数发行版上)提供类似的
功能。
更新:fswatch 现在可以在许多平台上使用,包括 BSD、Debian 和 Windows。
语法/一个简单的例子
可以观察多个路径的新方法 - 对于1.x 及更高版本:
fswatch -o ~/path/to/watch | xargs -n1 -I{} ~/script/to/run/when/files/change.sh
注意:如果不是-I{},-o 输出的数字将被添加到xargs 命令的末尾。如果您确实选择使用该号码,请将{} 放在您的命令中的任何位置。
版本 0.x 的旧方法:
fswatch ~/path/to/watch ~/script/to/run/when/files/change.sh
使用 Homebrew 安装
截至 2013 年 9 月 12 日,它已重新添加到 homebrew - 耶!因此,更新您的公式列表 (brew update),然后您需要做的就是:
brew install fswatch
不使用 Homebrew 安装
在Terminal.app中输入这些命令
cd /tmp
git clone https://github.com/alandipert/fswatch
cd fswatch/
make
cp fswatch /usr/local/bin/fswatch
如果您的系统上没有c 编译器,您可能需要安装 Xcode 或 Xcode 命令行工具 - 两者都是免费的。但是,如果是这种情况,您可能应该只使用check out homebrew。
fswatch 1.x 版的附加选项
Usage:
fswatch [OPTION] ... path ...
Options:
-0, --print0 Use the ASCII NUL character (0) as line separator.
-1, --one-event Exit fsw after the first set of events is received.
-e, --exclude=REGEX Exclude paths matching REGEX.
-E, --extended Use exended regular expressions.
-f, --format-time Print the event time using the specified format.
-h, --help Show this message.
-i, --insensitive Use case insensitive regular expressions.
-k, --kqueue Use the kqueue monitor.
-l, --latency=DOUBLE Set the latency.
-L, --follow-links Follow symbolic links.
-n, --numeric Print a numeric event mask.
-o, --one-per-batch Print a single message with the number of change events.
in the current batch.
-p, --poll Use the poll monitor.
-r, --recursive Recurse subdirectories.
-t, --timestamp Print the event timestamp.
-u, --utc-time Print the event time as UTC time.
-v, --verbose Print verbose output.
-x, --event-flags Print the event flags.
See the man page for more information.