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