[mac] .DS_Store 檔案, ._* 開頭的隱藏檔案

2019102023:34

.DS_Store (英文全稱 Desktop Services Store)

https://zh.wikipedia.org/wiki/.DS_Store
蘋果 Mac OS X 作業系統所創造的隱藏文件,用於存貯目錄的自定義屬性,如文件們的圖標位置或者是背景色的選擇。
該檔由 Finder 創建/維護,類似於 Microsoft Windows 中的 desktop.ini 檔

默認情況下,Mac OS X 的Finder程序會在進行存取的每個目錄下創建.DS_Store文件,甚至是在遠程系統上的目錄(例如通過SMB連接或者蘋果文件協議連接來共享的目錄),並且甚至如果用戶僅僅通過移動該目錄的Finder窗口自定義了其顯示。 這與既存的在先前版本的Finder中為了同樣目的所使用的方式的系統形成了對比,先前的只會放置一些不可見文件於卷的根目錄下(甚至在外部文件系統上),並總是將整個驅動器的所有目錄的設置與元數據存儲在這類文件的單一集合中。
在Mac OS X 10.5 "Leopard"發布前,.DS_Store文件在Windows的文件系統上是可見的。

白話來講:

.DS_Store 檔案是類似 windows 中的 desktop.ini / Thumbs.db兩個檔案
用來儲存 該資料夾的 icon、上次finder開啟這資料夾的視窗大小...等資訊,刪除掉 並無影響



在網路磁碟機上,被建立 .DS_Store,讓人覺得討厭,下列可以關閉 Mac OS 在網路磁碟建立 .DS_Store :
  • 禁止.DS_store生成:
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool TRUE
  • 恢復.DS_store生成:
defaults delete com.apple.desktopservices DSDontWriteNetworkStores
 
  • 刪除所有 .DS_Store 檔案
sudo find / -name ".DS_Store" -depth -exec rm {} \;




另外,目錄中一堆 ._ 開頭的隱藏檔案
依據蘋果的說法,只有 Mac OS X 10.0, Mac OS X 10.2  會產生這些檔案

https://web.archive.org/web/20120602061209/http://support.apple.com/kb/TA20578
Before Mac OS X, the Mac OS used 'forked' files, which have two components: a data fork and a resource fork. The Mac OS Standard (HFS) and Mac OS Extended (HFS Plus) disk formats support forked files. When you move these types of files to other disk formats, the resource fork can be lost.

With Mac OS X, there is a mechanism called "Apple Double" that allows the system to work with disk formats that do not have a forked file feature, such as remote NFS, SMB, WebDAV directories, or local UFS volumes. Apple Double does this by converting the file into two separate files. The first new file keeps the original name and contains the data fork of the original file. The second new file has the name of the original file prefixed by a "._ " and contains the resource fork of the original file. If you see both files, the ._ file can be safely ignored. Sometimes when deleting a file, the ._ component will not be deleted. If this occurs you can safely delete the ._ file.



清除這些檔案的方式

macos
dot_clean 路徑名稱

Linux
find . -type f -name '._*' -delete


https://apple.stackexchange.com/questions/60958/will-setting-a-cron-job-to-delete-shadow-files-on-a-linux-share-work

解析.DS_Store文件格式 - 知乎 (zhihu.com)