一般语境下的“苹果屎”是指.DS_Store,除此之外,macOS 在外置存储(FAT/exFAT 等)上会自动生成 ._ 开头的隐藏文件(Apple Double 文件),用于存储扩展属性和资源分支。
1. 命令行一键清理(推荐)
# 进入外置磁盘目录后执行
find . -name "._*" -type f -delete
# 或者指定路径
find /Volumes/你的磁盘名 -name "._*" -type f -delete
# 同时清理 .DS_Store
find . -name "._*" -o -name ".DS_Store" -type f -delete
find /Volumes/你的磁盘名 -name "._*" -o -name ".DS_Store" -type f -delete
2. 永久禁用(阻止生成)
# 关闭网络存储上的 ._ 文件生成
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
# 关闭 USB/FireWire 存储上的 ._ 文件生成
defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true
# 重启生效
killall Finder
3. 使用 dot_clean 合并/清理
# 将 ._ 文件合并回原文件后删除
dot_clean /Volumes/你的磁盘名
# -m 参数:合并后保留 ._ 文件(默认会删除)
dot_clean -m /Volumes/你的磁盘名
4. 格式化磁盘为 APFS/exFAT 的权衡
| 文件系统 | ._ 文件 | 兼容性 |
|---|---|---|
| APFS/HFS+ | ❌ 不生成 | 仅限 Mac |
| exFAT | ✅ 生成 | Mac/Win 通用 |
| FAT32 | ✅ 生成 | 全平台兼容 |
| NTFS | ❌ 不生成 | 需第三方工具写入 |
最佳实践:如果是跨平台使用的 U 盘/移动硬盘,建议先执行 defaults write 禁用生成,再用 find 清理已有文件。