- Published on
Prevent macOS from Creating .DS_Store Files on Network and USB Drives
- Authors

- Name
- Mick MacCallum
- @0x7fs
If you work with network drives or USB storage on macOS, you've likely encountered .DS_Store files appearing everywhere. These hidden files store Finder view preferences (icon positions, background images, etc.) and while useful on your local Mac, they can be problematic on shared network drives and USB storage.
These files can clutter version control repositories, cause sync issues, and are generally unnecessary on external storage. Fortunately, macOS provides a simple way to prevent their creation on network volumes and USB drives.
What Are .DS_Store Files?
.DS_Store (Desktop Services Store) files are hidden macOS system files that store custom attributes of folders, including:
- Icon positions and view settings
- Background images or colors
- Window size and position
- Sorting preferences
On your local Mac, these files help Finder remember how you like to view your folders. However, on network drives and USB storage, they're usually unwanted.
Preventing .DS_Store on Network Drives
To prevent macOS from creating .DS_Store files on network volumes, use this Terminal command:
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
This tells macOS to skip writing .DS_Store files on any mounted network share (SMB, AFP, NFS, etc.).
Making It Effective
After running the command, you need to restart Finder or log out and back in:
# Restart Finder
killall Finder
# Or restart your Mac
Verifying the Setting
Check if the setting is enabled:
defaults read com.apple.desktopservices DSDontWriteNetworkStores
If it returns 1 or true, the setting is active.
Preventing .DS_Store on USB Drives
For USB drives and other removable media, use a similar command:
defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true
Then restart Finder:
killall Finder
Apply Both Settings
Most developers want to prevent .DS_Store files on both network and USB drives. Here's a combined command:
# Prevent on network drives
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
# Prevent on USB drives
defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true
# Restart Finder
killall Finder
Cleaning Up Existing .DS_Store Files
These settings only prevent new .DS_Store files. To remove existing ones:
Remove from a Specific Directory
# Remove from current directory and subdirectories
find . -name ".DS_Store" -type f -delete
Remove from a Network Drive
# Replace /Volumes/NetworkDrive with your mount path
find /Volumes/NetworkDrive -name ".DS_Store" -type f -delete
Remove from a USB Drive
# Replace /Volumes/USBDrive with your drive name
find /Volumes/USBDrive -name ".DS_Store" -type f -delete
Adding to .gitignore
If you're working with Git repositories, always add .DS_Store to your .gitignore:
# Global .gitignore for all repositories
echo ".DS_Store" >> ~/.gitignore_global
git config --global core.excludesfile ~/.gitignore_global
Or add it to a project-specific .gitignore:
# Add to project .gitignore
echo ".DS_Store" >> .gitignore
Reverting the Changes
If you ever need 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
Integration with Dotfiles
Add to your dotfiles repository for automatic setup on new machines:
# In your .bash_profile, .zshrc, or setup script
if [ "$(defaults read com.apple.desktopservices DSDontWriteNetworkStores 2>/dev/null)" != "1" ]; then
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true
killall Finder 2>/dev/null
fi
Conclusion
Preventing .DS_Store files on network and USB drives is a simple one-time configuration that keeps your shared storage clean and your repositories tidy. Two Terminal commands and a Finder restart are all it takes to avoid these persistent files.
For development teams, making this part of your standard Mac setup ensures consistency across environments and prevents unnecessary file clutter in shared workspaces and version control systems.
