用于 Linux 中目录更改的 Watcherd Shell 侦听器
Watcherd 是 Linux 的一个工具,它有助于监视目录更改并打印所做的任何更改,例如为特定目录添加和删除,并根据特定事件执行命令和 shell 脚本。
在 Linux 上安装 Watcherd
第一步:下载watcherd。
由于 watcherd 是一个 Github 存储库,您可以使用 wget 命令下载其 zip 并解压缩。为此,请执行以下命令:
wget https://github.com/devilbox/watcherd/archive/master.zip
第二步:解压并解压。
下载后使用命令解压文件:
unzip master.zip
如果您不必解压缩安装,则可以使用以下方法安装它:
sudo apt-get install unzip
第 3 步:复制到 bin 位置。
解压完成后,您需要将文件复制到 bin 目录,为此使用命令:
sudo cp watcherd-master/watcherd /usr/bin/
第四步:检查工具是否安装正确。
您可以使用 help 命令查看用户手册:
watcherd --help
输出:
或者你可以检查 –version
watcherd --version
输出:
守望者工作:
第一步:创建目录。
在当前工作目录中创建一个名为 test 的目录
mkdir sample
第 2 步:现在启动 watcherd。
现在使用以下参数部署 watcherd:
watcherd -v -p ~/sample -a "echo added %n" -d "echo deleted %n" -t "ls -l ~/sample" &
输出:
where
- -v stands for verbose which will verbosify the output of the command
- -p stands for the path to directory, and we have used test for the subject
- -a stands for executing the command if any directory path is created , we have used echo for printing but you can also add any other way of scripting and make the best use out of it.
- -d stands for executing the command if any directory path is deleted and vice versa.
- %n will be substituted with directory name or you can use %p to get a full path to the created or deleted directory
- -t “ls -l ~/test” execute command after triggering
- & run in background
第 3 步:执行命令后,使用以下命令检查它是否正在运行:
ps ax | grep watcherd
输出:
现在让我们在测试文件夹中添加和删除目录,看看会发生什么,目录可以命名为任何名称,例如我们使用 anon。
mkdir sample/anon
输出:
rmdir sample/anon
输出:
执行该命令后,您将能够看到 watcherd 生成的输出。