DS Store
Key Takeaways
.DS_Store is a hidden metadata file created by macOS to store folder view options and icon positions. It can accumulate across directories, increasing disk usage, leaking metadata, and causing sync conflicts. Understanding its structure, lifecycle, and removal strategies is essential for developers, system administrators, and power users.
What is a .DS_Store File?
The .DS_Store (Desktop Services Store) file is automatically generated by the Finder when a directory is accessed. It records:
- Icon placement and size
- Folder view settings (list, column, icon, grid)
- Custom folder icons
- Thumbnail caches for images, videos, and PDFs
- Sorting preferences and column configurations
These data are stored in a proprietary binary format and are not human-readable without specialized tools.
Why Should You Care?
While harmless for local use, .DS_Store files can:
- Increase storage consumption—especially on network shares and cloud drives.
- Expose private metadata when shared externally.
- Cause synchronization conflicts in version control systems and cloud services.
- Hinder performance on older hardware due to excessive disk reads.
Common Scenarios Where .DS_Store Becomes a Problem
- Collaborative projects on Git, SVN, or Mercurial.
- Shared network drives accessed by Windows or Linux clients.
- Automated backup and sync tools like rsync, Dropbox, or iCloud.
- Mac OS X servers hosting web or file services.
Data Comparison: .DS_Store vs. Other Hidden Files
| File Type | Purpose | Typical Size | Frequency of Creation | Common Impact |
|---|---|---|---|---|
.DS_Store |
Folder view metadata | ~5–10 KB per folder (can grow with thumbnails) | Every time a folder is opened in Finder | Disk clutter, metadata leakage |
.AppleDouble |
Resource fork backup for non-Apple systems | Variable, often <10 KB | When copying files to non-Apple OS | Redundant storage, potential conflicts |
.AppleDB |
Database for Spotlight indexing | Several MBs per volume | On first boot, after file changes | Large index size, slower searches |
.fseventsd |
File system event logs | 10–100 KB per volume | Continuous as files change | Potential privacy concerns, large logs |
._* |
Metadata for non-Apple files (macOS resource forks) | Variable, often <5 KB | When transferring files to other OS | Unnecessary clutter on non-Apple systems |
Best Practices for Managing .DS_Store
Preventing Creation on Network Drives
- Open Terminal and run:
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true - Restart Finder:
killall Finder - Verify with
defaults read com.apple.desktopservices DSDontWriteNetworkStores(should return1)
Removing Existing .DS_Store Files
- On a local folder:
find . -name '*.DS_Store' -delete - On a network share:
find /path/to/share -name '*.DS_Store' -delete - For Git repositories: add
*.DS_Storeto.gitignore
Automating Cleanup with Cron or LaunchDaemons
Create a script that runs nightly:
# /usr/local/bin/cleanup_ds_store.sh
find / -type f -name '*.DS_Store' -delete
Set up a cron job:
0 2 * * * /usr/local/bin/cleanup_ds_store.sh
Checklist for System Administrators
- [ ] Disable network
.DS_Storecreation on all macOS clients. - [ ] Add
.DS_Storeto global.gitignoreand.hgignore. - [ ] Schedule nightly cleanup on network shares.
- [ ] Educate users about the purpose and harmless nature of
.DS_Store. - [ ] Monitor disk usage trends to detect unusual growth.
Advanced Topics
Inspecting .DS_Store Contents
Use ds_store_extractor (Python package) to decode the binary format:
pip install ds_store_extractor
ds_store_extractor path/to/folder
This reveals icon positions, view modes, and thumbnail hashes.
Security Implications
Because .DS_Store may contain thumbnail hashes and folder icons, leaking them can expose the presence of sensitive files or folder structures. In regulated environments, enforce strict file filtering policies.
FAQs
1. Can I permanently stop macOS from creating .DS_Store files?
On local disks, macOS will always generate .DS_Store to store view preferences. The only practical approach is to ignore, delete, or archive them. For network shares, the DSDontWriteNetworkStores setting disables creation.
2. Will removing .DS_Store files affect my Finder experience?
Only the specific folder's view settings will revert to defaults (grid view, default icon size). Custom icons and view preferences will be lost, but the file system remains unaffected.
3. Why do some Git repositories still contain .DS_Store files?
Occasionally, developers commit them inadvertently before adding .DS_Store to .gitignore. Once committed, you need to remove them from the repository history using git filter-branch or bfg repo-cleaner to purge them.