ubuntu下inotifywait实现目录、文件监控【包含子目录】
inotifywait命令
【命令格式】: inotifywait [ options ] file1 [ file2 ] [ file3 ] [ … ]
【命令原意】: inote file system wait
【命令路徑】:
【命令功能】: 等待所監聽的文件系統觸發操作事件
【執行權限】: root
【命令描述】:
眾所周知,Linux 桌面系統與 MAC 或 Windows 相比有許多不如人意的地方,為了改善這種狀況,開源社區提出用戶態需要內核提供一些機制,以便用戶態能夠及時地得知內核或底層硬件設備發生了什么,從而能夠更好地管理設備,給用戶提供更好的服務,如 hotplug、udev 和 inotify 就是這種需求催生的。Hotplug 是一種內核向用戶態應用通報關于熱插拔設備一些事件發生的機制,桌面系統能夠利用它對設備進行有效的管理,udev 動態地維護 /dev 下的設備文件,inotify 是一種文件系統的變化通知機制,如文件增加、刪除等事件可以立刻讓用戶態得知,該機制是著名的桌面搜索引擎項目 beagle 引入的,并在 Gamin 等項目中被應用。
【常用選項】:
-h 或 --help 顯示幫助
【總結提示】:
Exit status: 退出返回狀態值
0 - An event you asked to watch for was received.
正常收到監聽事件
1 - An event you did not ask to watch for was received (usually delete_self or unmount), or some error occurred.
意外收到一個未監聽的事件(如:文件自刪除,umount及其它情況)
2 - The --timeout option was given and no events occurred in the specified interval of time.
當給定了超時選項,設定時間內沒有事件產生
Events: 事件
access file or directory contents were read 文件或目錄被(訪問)讀取r
modify file or directory contents were written 文件或目錄被寫入w
attrib file or directory attributes changed 文件或目錄屬性變更【理由:chmod更改屬性】
close_write file or directory closed, after being opened in writeable mode 文件或目錄被寫關閉【理由:文件內容被更改】
close_nowrite file or directory closed, after being opened in read-only mode 文件或目錄以只讀方式打開后關閉
close file or directory closed, regardless of read/write mode 文件或目錄被用編輯器(不管是讀或寫)關閉
open file or directory opened 文件或目錄被用編輯器打開
moved_to file or directory moved to watched directory 文件或目錄被移動進來【理由:mv目錄內重命名】
moved_from file or directory moved from watched directory 文件或目錄被移動出去
move file or directory moved to or from watched directory 文件或目錄不管是移出或移進
create file or directory created within watched directory 文件或目錄被創建【理由:mkdir創建目錄】
delete file or directory deleted within watched directory 文件或目錄被刪除【理由:rm刪除】
delete_self file or directory was deleted 文件或目錄自刪除
unmount file system containing file or directory unmounted 文件系統取消掛載
總結
以上是生活随笔為你收集整理的ubuntu下inotifywait实现目录、文件监控【包含子目录】的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 麻辣香锅都有什么食材 麻辣香锅都有哪些食
- 下一篇: Ubuntu 免密登录