Mac OS X 在掛載某些檔案系統時;為了記錄檔案資訊,會產生很多 .* 檔案。
例:
/Volumes/ABEILLE/.DS_Store
/Volumes/ABEILLE/._.DS_Store
/Volumes/ABEILLE/港自殺率高於全球平均.html
/Volumes/ABEILLE/._港自殺率高於全球平均.html
/Volumes/ABEILLE/自殺.html
/Volumes/ABEILLE/._自殺.html
/Volumes/ABEILLE/青少年對「自殺行為」的態度與看法.html
/Volumes/ABEILLE/._青少年對「自殺行為」的態度與看法.html
其中 ABEILLE 為 USB 隨身碟的名稱。若此隨身碟拿到 PC 上 ,會看到很多 .* 檔案,令人煩惱。
刪除這些 .* 檔案的 shell command 為:
代碼:
$ find pathToVolume -name '.*' -exec rm -f {} \;
其中 pathToVolume 為檔案系統的絕對路徑;若掛載點為 /Volumes,循上例:
代碼:
$ find /Volumes/ABEILLE -name '.*' -exec rm -f {} \;
若不欲每次輸入指令,卸載檔案系統前可執行這 [url=applescript://com.apple.scripteditor/?action=new&script=tell%20application%20%22System%20Events%22%20to%20set%20targetDisk%20to%20name%20of%20disks%20whose%20ejectable%20is%20true%20and%20not%20%28format%20is%20audio%20format%29%0D%0Drepeat%20with%20i%20in%20targetDisk%0D%09set%20chosenDisk%20to%20quoted%20form%20of%20POSIX%20path%20of%20%28contents%20of%20i%29%0D%09set%20cmd%20to%20%28%22diskutil%20info%20%22%20as%20Unicode%20text%29%20%26%20chosenDisk%20%26%20%22%20%7C%20grep%20Protocol%22%0D%09if%20word%20%2D1%20of%20%28do%20shell%20script%20cmd%29%20%3D%20%22USB%22%20then%0D%09%09try%20%2D%2D%20delete%20%2E%2A%20files%0D%09%09%09set%20dcmd%20to%20%28%22find%20%22%20as%20Unicode%20text%29%20%26%20chosenDisk%20%26%20%22%20%2Dname%20%27%2E%2A%27%20%2Dexec%20rm%20%2Df%20%7B%7D%20%5C%5C%3B%22%0D%09%09%09do%20shell%20script%20dcmd%0D%09%09end%20try%0D%09end%20if%0Dend%20repeat%0Dsay%20%22done%22%0D]applescript[/url];會自行偵測 可退出、使用 USB 的卷宗,並刪除所有.* 檔案。
代碼:
tell application "System Events" to set targetDisk to name of disks whose ejectable is true and not (format is audio format)
repeat with i in targetDisk
set chosenDisk to quoted form of POSIX path of (contents of i)
set cmd to ("diskutil info " as Unicode text) & chosenDisk & " | grep Protocol"
if word -1 of (do shell script cmd) = "USB" then
try -- delete .* files
set dcmd to ("find " as Unicode text) & chosenDisk & " -name '.*' -exec rm -f {} \\;"
do shell script dcmd
end try
end if
end repeat
say "done"