fswatch是一个开源、跨平台的文件更改监视器,可以查看指定文件或目录是否被更改,如果文件或目录发生变化会发送通知。支持Linux/Unix、Windows和macOS系统。
fswatch源代码(C++):https://github.com/emcrisostomo/fswatch
还有一个使用Go编写的同名项目:https://github.com/codeskyblue/fswatch
fswatch is a file change monitor that receives notifications when the contents of the specified files or directories are modified.
Linux安装fswatch
fswatch并没有现成的Linux安装包,只能编译安装。
首先安装一些基本开发工具,如C、C++、make等:
apt-get install build-essential # Debian/Ubuntu
yum group install 'Development Tools' # CentOS/RHEL
dnf group install 'Development Tools' # Fedora 22+
下载fswatch源代码:
$ wget https://github.com/emcrisostomo/fswatch/releases/download/1.9.3/fswatch-1.9.3.tar.gz
$ tar -xvzf fswatch-1.9.3.tar.gz
编译安装:
$ cd fswatch*
$ ./configure
$ make
$ sudo make install
fswatch的使用
语法:
$ fswatch [option] [path]
查看可使用的monitor:
默认是inotify。
示例:
$ fswatch -l 1 .
$ fswatch -l 5 /var/log/auth.log
更多选项查看帮助:
$ man fswatch