Why Does Mac Create .DS_Store Files?

.DS_Store (Desktop Services Store) files are hidden metadata files created automatically by macOS Finder. They store custom view settings for folders—icon positions, background images, window size, and sort order. While useful on Macs, these files cause problems when shared with Windows users or uploaded to web servers, appearing as visible clutter.

Quick Answer: .DS_Store files are harmless and safe to delete. They'll be recreated automatically when you next open the folder in Finder, but deleting them won't cause data loss or system problems.

What Are .DS_Store Files?

Desktop Services Store files are binary property list files created by macOS Finder (the Mac file manager). They store folder-specific preferences and metadata.

What .DS_Store files contain:

  • Icon positions: Where you've arranged icons in icon view
  • View settings: Icon vs. list vs. column vs. gallery view
  • Sort order: How files are sorted (name, date, size)
  • Background image: Custom folder backgrounds
  • Window size: Preferred Finder window dimensions
  • Scroll position: Where you last scrolled in the folder
  • Desktop icon positions: Desktop file and folder locations
  • Spotlight comments: User-added file comments

These files are analogous to Windows' desktop.ini and thumbs.db files, which serve similar purposes for customizing folder views on Windows systems.

File Details

  • Full name: .DS_Store (the dot makes it hidden on Unix systems)
  • Size: Typically 6-12 KB, can grow larger with extensive metadata
  • Location: Created in every folder you open in Finder
  • Format: Binary plist (property list)
  • Created by: Finder in macOS (and OS X before it)

Why .DS_Store Files Cause Problems

1. Visible on Non-Mac Systems

Windows and Linux don't hide files starting with dots by default. When Mac users share folders, .DS_Store files appear as regular files, cluttering directories and confusing non-Mac users.

Common complaints from Windows users:

  • "What are these weird .DS_Store files?"
  • "Why can't I delete them? They keep coming back!"
  • "Are these viruses or malware?"
  • "They're showing up in my project folders and breaking builds"

2. Uploaded to Web Servers

When uploading websites via FTP or file transfer, .DS_Store files are often uploaded unintentionally. They become publicly accessible, potentially exposing folder structure information.

Security researchers can download /.DS_Store from web servers to discover hidden files and directory structures that weren't meant to be public.

3. Version Control Clutter

In Git, SVN, or other version control systems, .DS_Store files get committed accidentally, creating unnecessary diff noise and merge conflicts. Every Mac developer on a team might have different view preferences, causing constant changes to these files.

4. ZIP Archive Pollution

When Mac users create ZIP files, .DS_Store files are included. Recipients on other platforms see these as extra files they didn't expect, alongside the actual content they wanted.

5. Cloud Storage Sync Issues

Services like Dropbox, Google Drive, and OneDrive sync .DS_Store files, wasting bandwidth and storage. With thousands of folders, these small files add up and trigger unnecessary sync operations.

How to View .DS_Store Files

By default, macOS hides .DS_Store files in Finder. To see them:

Show Hidden Files in Finder:

Keyboard Shortcut (Temporary):

  1. Open Finder
  2. Press Command (⌘) + Shift + . (period)
  3. Hidden files including .DS_Store now visible (grayed out)
  4. Press same shortcut again to hide them

Terminal Command (Permanent):

defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder

To hide again:

defaults write com.apple.finder AppleShowAllFiles FALSE
killall Finder

How to Delete .DS_Store Files

Method 1: Delete Individual Files

After making hidden files visible, you can delete .DS_Store files like any other file:

  • Right-click the .DS_Store file
  • Select Move to Trash
  • Empty Trash to permanently delete

Method 2: Delete All .DS_Store Files (Terminal)

Remove All .DS_Store Files:

From Specific Folder:

cd /path/to/folder
find . -name ".DS_Store" -delete

From Entire Home Directory:

find ~ -name ".DS_Store" -delete

From Entire System (requires sudo):

sudo find / -name ".DS_Store" -delete 2>/dev/null

Alternative with confirmation:

find . -name ".DS_Store" -exec rm -i {} \;

The -i flag prompts you to confirm each deletion.

Method 3: Automated Deletion Script

Create a script to run regularly:

#!/bin/bash
# Save as ~/bin/clean-dsstore.sh
find ~/Documents ~/Desktop ~/Downloads -name ".DS_Store" -delete
echo ".DS_Store files cleaned!"

Make it executable: chmod +x ~/bin/clean-dsstore.sh

How to Prevent .DS_Store Creation

Disable on Network Drives

macOS creates .DS_Store on network drives (SMB, AFP, NFS), annoying Windows network users. Disable this:

Prevent .DS_Store on Network Volumes:

defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool TRUE
killall Finder

To re-enable (if needed):

defaults delete com.apple.desktopservices DSDontWriteNetworkStores
killall Finder

Disable on USB Drives

Similarly, prevent creation on external USB drives:

defaults write com.apple.desktopservices DSDontWriteUSBStores -bool TRUE
killall Finder

Note

Disabling .DS_Store creation means Finder won't remember your custom view settings for those locations. You'll lose icon positions, custom backgrounds, and view preferences on network and USB drives.

Cannot Fully Disable on Local Drives

Apple provides no official way to completely disable .DS_Store creation on your Mac's internal drive. Finder requires them for proper operation. Third-party utilities claiming to disable them often cause system instability.

Exclude from Git Repositories

Prevent .DS_Store files from being committed to version control:

Add to .gitignore:

For Single Repository:

Add to your project's .gitignore file:

.DS_Store

Global .gitignore (All Repositories):

# Create global gitignore file
echo ".DS_Store" >> ~/.gitignore_global

# Configure Git to use it
git config --global core.excludesfile ~/.gitignore_global

Remove Already-Committed .DS_Store Files:

# Remove from Git tracking but keep local file
git rm --cached .DS_Store
find . -name .DS_Store -print0 | xargs -0 git rm --cached --ignore-unmatch

# Commit the removal
git commit -m "Remove .DS_Store files"
git push

Exclude from ZIP Archives

Create clean ZIP files without .DS_Store:

# Instead of right-click → Compress
# Use Terminal command:
zip -r archive.zip folder/ -x "*.DS_Store"

For excluding multiple Mac-specific files:

zip -r archive.zip folder/ -x "*.DS_Store" -x "__MACOSX"

Third-Party Tools

Asepsis (Discontinued)

Previously popular utility that redirected .DS_Store files to a central location. No longer maintained and incompatible with modern macOS due to System Integrity Protection.

BlueHarvest

Paid application ($15) that prevents .DS_Store creation on specific volumes and cleans existing files automatically. Works with modern macOS versions.

DS_Store Cleaner

Free utility with GUI for finding and deleting .DS_Store files. Simpler than Terminal commands for non-technical users.

Understanding Related Mac Files

macOS creates several hidden files that often accompany .DS_Store:

  • .AppleDouble: Stores resource forks when copying files to non-Mac volumes
  • ._filename: AppleDouble files containing extended attributes and metadata
  • .Spotlight-V100: Spotlight search index data
  • .Trashes: Trash folder on external drives
  • .fseventsd: File system events used by Time Machine
  • .VolumeIcon.icns: Custom volume icons
  • __MACOSX: Resource fork folder in ZIP archives created on Mac

These files serve similar purposes—maintaining macOS-specific features on file systems that don't natively support Mac metadata.

Should You Delete .DS_Store Files?

Yes, delete them when:

  • Sharing folders with Windows/Linux users
  • Uploading to web servers
  • Creating ZIP archives for distribution
  • Committing to version control
  • Cleaning up cloud storage

No need to delete when:

  • Working solely on your Mac
  • Folders are only for personal use
  • You rely on custom Finder view settings

What Happens When Deleted

Deleting .DS_Store files is completely safe. You won't lose any actual data—only Finder view preferences. The files will be automatically recreated when you next open the folder in Finder. Think of them like browser cookies for folder viewing preferences.

Professional Development Best Practices

For developers and IT professionals:

  • Always add .DS_Store to .gitignore
  • Configure build systems to exclude Mac metadata files
  • Document Mac-specific quirks for cross-platform teams
  • Use rsync with --exclude=.DS_Store for deployments
  • Configure CI/CD pipelines to reject commits containing .DS_Store
  • Use find commands in deployment scripts to remove Mac metadata

Pro Tip

Create an Alfred workflow or shell alias for quickly cleaning .DS_Store files from your projects. Example alias for ~/.zshrc or ~/.bash_profile:

alias cleanup="find . -type f -name '*.DS_Store' -ls -delete"