防止macOS中Spotlight在移动硬盘或者U盘中创建索引

禁止用做时间机器备份

1
touch .com.apple.timemachine.donotpresent

.fseventsd 文件夹:文件系统日志记录

可在.fseventsd文件夹下面建立no_log文件来取消这个功能

.ds_store 文件

  • 防止在 USB 存储设备中创建.ds_store 文件
1
defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true
  • 防止在网络驱动器中创建.ds_store 文件
1
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true

._开头的文件

https://apple.stackexchange.com/questions/136248/disable-storage-of-invisible-files-on-my-cfs-or-smb-network-storage

  • 删除已存在的文件
1
dot_clean /path/

.DocumentRevisions-V100 Spotlight 索引文件

在移动硬盘或者U盘根目录创建.metadata_never_index文件

1
2
3
4
# macOS
touch .metadata_never_index
# Windows
type nul>.metadata_never_index

给这个文件添加保护

1
chmod 444 ./.metadata_never_index

这些文件或者文件夹的作用:http://blog.hostilefork.com/trashes-fseventsd-and-spotlight-v100/

其他解决方案
参考:https://forums.macrumors.com/threads/solved-prevent-hidden-files-creation-on-usb-drives.2022099/
You can try this out. It may still include .fsevents, .DocumentRevisions, .TemporaryItems and .Trashes. I kind of think it may be unavoidable to create certain file system structures when introducing a volume. The Spotlight stuff and the .ds_stores you can take care of though. Try these out and see if they help. Probably best in the order their given but I really can’t verify if it matters or not.

Prevent MDS from attempting to Index

1
sudo touch /Volumes/your volume name here/.metadata_never_index

Disable Indexing AND Searching of Volumes

1
sudo mdutil -i off -d /Volumes/your volume name here

Delete existing Spotlight Index

1
sudo rm -rfv /.Spotlight-V100

Disable creating ‘.ds_store’ on USB volumes

1
defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true

Disable creating ‘.ds_store’ on network volumes

1
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true

Sorry if this makes your machine explode, implode, hack NORAD, “Friends” you with Justin Bieber or any other unexpected results.

关闭所有内置磁盘的 Spotlight 索引

sudo mdutil -a -i off

关闭外部硬盘的 Spotlight 索引

sudo defaults write /Library/Preferences/com.apple.SpotlightServer.plist ExternalVolumesIgnore -bool True

防止在网络驱动器上创建.DS_Store 文件

defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool TRUE


防止macOS中Spotlight在移动硬盘或者U盘中创建索引
https://dnacore.github.io/post/0f54aaf5-f299-4282-9990-c137b4adf288.html
作者
DNACore
发布于
2018年12月29日
更新于
2025年3月10日
许可协议