No .DS_Store Files
.DS_Store (Desktop Services Store) files are hidden macOS system files that store custom attributes of folders, including:
- Icon positions and sizes
- View mode (icon, list, column)
- Window size and position
- Sorting/grouping preferences
- Background images for folders
.DS_Store files help to provide a consistent and personalized user experience in macOS, similar to desktop.ini files in Windows.
While they’re useful on a Mac’s local drive, they’re often undesirable on network shares, USB drives, or in cross-platform environments, where they can clutter directories and reduce performance.
1 To prevent .DS_Store files being created on network and/or USB drives:
# Prevent .DS_Store on network drives defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true # Prevent .DS_Store on USB drives defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true # Restart Finder killall Finder
2 To check the settings:
# For network drives defaults read com.apple.desktopservices DSDontWriteNetworkStores # For USB drives defaults read com.apple.desktopservices DSDontWriteUSBStores
3 To restore the default behavior:
# Re-enable .DS_Store on network drives defaults delete com.apple.desktopservices DSDontWriteNetworkStores # Re-enable .DS_Store on USB drives defaults delete com.apple.desktopservices DSDontWriteUSBStores # Restart Finder killall Finder
4 To find and delete .DS_Store files recursively on a mounted drive:
# Replace /Volumes/Drive with your mount path find "/Volumes/Drive" -name ".DS_Store" -delete
To delete only files (no directories), and print the pathname:
find "/Volumes/Drive" -name ".DS_Store" -type f -print -delete
Alternatively, change to the directory and use 'find' there (.):
cd to/directory find . -name '.DS_Store' -type f -delete
- Optionally omit
-deleteinitially to verify the list of files that will be deleted. - If you haven't performed step 1 above, the Finder will automatically re-create the files!