在CentOS上安裝inotify-tools的步驟如下:
更新系統包列表
sudo yum update -y
安裝EPEL倉庫(如果尚未安裝) EPEL(Extra Packages for Enterprise Linux)提供了許多額外的軟件包,包括inotify-tools。
sudo yum install epel-release -y
安裝inotify-tools
sudo yum install inotify-tools -y
驗證安裝 安裝完成后,可以通過以下命令檢查inotifywait和inotifywatch是否可用:
which inotifywait
which inotifywatch
如果你需要特定版本的inotify-tools或者yum倉庫中沒有該軟件包,可以選擇從源碼編譯安裝。
安裝依賴項
sudo yum groupinstall "Development Tools" -y
sudo yum install kernel-devel -y
下載inotify-tools源碼 訪問inotify-tools的GitHub頁面,找到最新版本的源碼并下載。
wget https://github.com/rvoicilas/inotify-tools/archive/v0.9.6.tar.gz
解壓源碼
tar -zxvf v0.9.6.tar.gz
cd inotify-tools-0.9.6
編譯并安裝
./configure
make
sudo make install
驗證安裝 同樣,通過以下命令檢查inotifywait和inotifywatch是否可用:
which inotifywait
which inotifywatch
安裝完成后,你可以使用inotifywait和inotifywatch來監控文件系統事件。
inotifywait -m /path/to/directory -e create,delete,modify
這個命令會持續監控指定目錄,并在檢測到創建、刪除或修改事件時輸出相關信息。
inotifywatch -m -r -e create,delete,modify /path/to/directory 60
這個命令會每60秒輸出一次指定目錄及其子目錄的事件統計信息。
通過以上步驟,你應該能夠在CentOS上成功安裝并使用inotify-tools。