
我目前正在監視帶有子目錄的目錄,並且需要檢測文件重命名。我所做的就是對所有檔案進行 md5sum 並將檔案清單保存在另一個位置,並且時不時地再次檢查 md5sums 是否有檔案變更是新增或重新命名。
這個過程很繁重,我想一定有更簡單的方法來偵測重命名。
答案1
你可以嘗試inotify工具。它可用於多種類似 Linux 的作業系統。
它的工作原理是向目錄添加“監視”,指定要偵聽的事件。關於這個主題的一篇可愛的文章可以在以下位置找到:https://www.linuxjournal.com/content/linux-filesystem-events-inotify
從線上說明頁:
DESCRIPTION
The inotify API provides a mechanism for monitoring file system events. Inotify can be used to monitor individual files, or to
monitor directories. When a directory is monitored, inotify will return events for the directory itself, and for files inside the
directory.
答案2
你有沒有嘗試過助理?我認為這對你的情況會有幫助。
# apt install aide [On Debian/Ubuntu]
# yum install aide [On RHEL/CentOS]
# dnf install aide [On Fedora 22+]
# zypper install aide [On openSUSE]
# emerge aide [On Gentoo]