
我使用拖放來複製和移動文件。其缺點之一是檔案可能最終到達錯誤的位置。因此,假設我將許多文件和資料夾複製/移動到多個不同的目的地。
我如何追蹤所有內容的最終位置以確保所有內容都被複製/移動到正確的位置?
答案1
您要求的是“檔案系統觀察者”。
我看 
iWatch 是一個即時檔案系統監控程式。這是一個簡單的 Perl 腳本,用於監視特定目錄/文件中的變更並立即發送電子郵件通知。它從 xml 設定檔讀取目錄/檔案列表,並且需要核心中的 inotify 支援(Linux Kernel >= 2.6.13)。
還有更多,但這似乎是最簡單的方法,是 Ubuntu 原生的並使用 inotify (因此它不會佔用系統)。
iWatch 有 2 種方法:
- 命令列
- 守護程式
用於記錄日誌的一些命令列選項:
-m <email address>
Specify the contact point's email address. Without this option, iwatch will
not send any email notification.
-s <on|off>
Enable or disable reports to the syslog (default is off/disabled)
iwatch /tmp
使用預設事件監視 /tmp 目錄中的更改
iwatch -r -e access,create -m cahya@localhost -x /etc/mail /etc
僅以 /etc/mail 為例外,以遞歸方式監視 /etc 目錄中的存取和建立事件,並將電子郵件通知發送到 cahya@localhost。
iwatch -r -c "(w;ps -ef)|mail -s '%f was changed' cahya@localhost" /bin
遞歸監控/bin目錄並執行指令。
iwatch -r -X '\.svn' ~/projects
遞歸監視 ~/projects 目錄,但排除其中的任何 .svn 目錄。這不能使用普通的“-x”選項來完成,因為“-x”只能排除定義的路徑。
設定檔範例當使用守護程式模式時。日誌記錄是透過設定檔中的 XML 選項完成的:
<config>
<guard email="myadmin@localhost" name="IWatch"></guard>
<watchlist>
<title>Public Website</title>
<contactpoint email="webmaster@localhost" name="Web Master"/>
<path type="single">/var/www/localhost/htdocs</path>
<path type="single" syslog="on">/var/www/localhost/htdocs/About</path>
<path type="recursive">/var/www/localhost/htdocs/Photos</path>
</watchlist>
<watchlist>
<title>Operating System</title>
<contactpoint email="admin@localhost" name="Administrator"/>
<path type="recursive">/etc/apache2</path>
<path type="single">/etc/passwd</path>
<path type="recursive">/etc/mail</path>
<path type="exception">/etc/mail/statistics</path>
<path type="single" filter="shadow|passwd">/etc</path>
</watchlist>
<watchlist>
<title>Only Test</title>
<contactpoint email="root@localhost" name="Administrator"/>
<path type="single" alert="off" exec="(w;ps -ef)|mail -s %f
root@localhost">/tmp/dir1</path>
<path type="single" events="access,close" alert="off" exec="(w;ps -ef)|mail -s %f
root@localhost">/tmp/dir2</path>
<path type="single" events="default,access" alert="off" exec="(w;ps -ef)|mail -s '%f is
accessed' root@localhost">/tmp/dir3</path>
<path type="single" events="all_events" alert="off">/tmp/dir4</path>
</watchlist>
</config>
透過此配置,iwatch 將監視單一目錄/var/www/localhost/htdocs
而不包含其子目錄,並且任何通知都會傳送至聯絡點 webmaster@localhost。但它會監視 的整個目錄樹/etc/apache2
,包括 IWatch 啟動後建立的任何子目錄。如果您不想收到受監視目錄內的檔案或子目錄的通知,您也可以在此處使用建立例外。