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