.DS_Store 為 Finder 儲存資料夾檢視設定(圖示位置、背景、排序等)的隱藏檔,常汙染 Git 倉庫、壓縮檔、網路分享。全盤刪除指令:
sudo find / -name ".DS_Store" -depth -exec rm {} \;
sudo:需管理員權限存取系統資料夾。find /:從根目錄遞迴搜尋(含外接磁碟)。-name ".DS_Store":比對檔名。-depth:先處理檔案再處理目錄,避免目錄被刪導致找不到檔案。-exec rm {} \;:對每個結果執行刪除。
僅清理特定專案/資料夾,避免誤刪系統/其他使用者設定:
# 僅清理當前專案
find ~/Projects/MyProject -name ".DS_Store" -delete
# 清理家目錄(較安全)
find ~ -name ".DS_Store" -delete
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true。defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true。.gitignore 加入 .DS_Store。