是的,CentOS(和其他类Unix系统)的inotify 支持监控符号链接
要在 CentOS 上使用 inotify 监控符号链接,请遵循以下步骤:
- 确保您的系统已安装 inotify-tools。如果尚未安装,请运行以下命令进行安装:
sudo yum install inotify-tools
- 创建一个名为
monitor_symlinks.sh
的脚本文件,并将以下内容粘贴到其中:
#!/bin/bash # 检查参数数量 if [ "$#" -ne 1 ]; then echo "Usage: $0" exit 1 fi directory=$1 # 使用 inotifywait 监控符号链接 inotifywait -m -r -e create -e modify -e moved --format '%w%f' "$directory" | while read file; do # 检查是否为符号链接 if [ -L "$file" ]; then echo "Symbolic link created or modified: $file" fi done
- 为脚本文件添加可执行权限:
chmod +x monitor_symlinks.sh
- 运行脚本并监控指定的目录:
./monitor_symlinks.sh /path/to/directory
现在,脚本将监控指定的目录及其子目录中的符号链接的创建和修改事件。当检测到这些事件时,它将输出相关信息。