是的,CentOS(和其他類Unix系統)的inotify 支持監控符號鏈接
要在 CentOS 上使用 inotify 監控符號鏈接,請遵循以下步驟:
sudo yum install inotify-tools
monitor_symlinks.sh 的腳本文件,并將以下內容粘貼到其中:#!/bin/bash
# 檢查參數數量
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <directory>"
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
現在,腳本將監控指定的目錄及其子目錄中的符號鏈接的創建和修改事件。當檢測到這些事件時,它將輸出相關信息。