Sweepfor Mac

Free up storage

How to Bulk-Delete Every .DS_Store File on Your Mac

Find and remove every .DS_Store file across your Mac in one Terminal command. Stop polluting zip archives, remote folders, and shared repositories.

7 min read

.DS_Store files are Finder’s invisible bookkeeping. Every time you view a folder in Finder, macOS drops a .DS_Store file inside it to remember things like window position, view mode, custom icon assignments, and column widths. They’re tiny — usually 6-15KB each — but they multiply rapidly. A Mac that’s been used for years can have 50,000+ of them.

The annoyance isn’t disk space. It’s that .DS_Store files leak into:

  • Zip archives you send to non-Mac users
  • Git repositories where they shouldn’t be
  • Shared network folders
  • USB drives
  • Cloud storage syncs
  • Project bundles you publish

Here’s how to find every .DS_Store, delete them in bulk, and stop them from being created where you don’t want them.

The one command everyone needs

To delete every .DS_Store in your home folder:

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

Breakdown:

  • ~ — your home folder
  • -name ".DS_Store" — files matching exactly that name
  • -delete — remove them
  • 2>/dev/null — silence permission errors

For the entire system (requires admin):

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

Both commands run silently. To see what would be deleted before actually deleting:

find ~ -name ".DS_Store" 2>/dev/null

That just lists the files without removing them.

Counting them first

Curiosity is reasonable. Before bulk deletion, see how many you’re dealing with:

find ~ -name ".DS_Store" 2>/dev/null | wc -l

Typical numbers:

  • New Mac (under 6 months): 500-2,000
  • Average Mac (1-3 years): 3,000-15,000
  • Old Mac (3+ years): 15,000-100,000

Don’t be alarmed by high numbers. .DS_Store files take negligible space — total bytes for 50,000 files is usually under 500MB.

Deleting from a specific folder

To clean just one project folder:

find /path/to/project -name ".DS_Store" -delete 2>/dev/null

Useful before zipping a folder to send to someone:

find ~/Desktop/MyProject -name ".DS_Store" -delete 2>/dev/null
zip -r MyProject.zip ~/Desktop/MyProject

Or as a one-liner that cleans then zips:

find ~/Desktop/MyProject -name ".DS_Store" -delete 2>/dev/null && zip -r MyProject.zip ~/Desktop/MyProject -x "*.DS_Store"

The -x "*.DS_Store" is belt-and-suspenders — even if cleanup missed any, the zip exclusion catches them.

Tip: Finder recreates .DS_Store files instantly when you view folders. Deletion is a snapshot in time, not a permanent fix.

Preventing creation on network drives

The most common .DS_Store annoyance is leaking onto network shares used by non-Mac coworkers. Apple has a setting for this:

defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true

This tells Finder to not create .DS_Store files on network volumes (SMB, AFP, NFS shares). Local drives are unaffected.

Restart Finder for the change to take effect:

killall Finder

To revert:

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

This is one of the most useful Mac tweaks for anyone working in a mixed-platform office.

Preventing creation on USB drives

Similar setting for USB drives and other external storage:

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

This stops Finder from creating .DS_Store on connected USB drives. Useful for thumb drives shared with Windows or Linux users.

Note that some USB drives are formatted as exFAT or FAT32, where .DS_Store creation also produces those ._ AppleDouble companion files. The setting above prevents both.

Preventing creation in cloud sync folders

Cloud folders are technically local, so the network setting doesn’t apply. But they sync to other devices, and .DS_Store files cause confusion in:

  • Dropbox shared folders
  • Google Drive shared folders
  • OneDrive shared folders

There’s no per-folder Finder setting. The workarounds:

Option 1: Add .DS_Store to each cloud service’s ignore list.

  • Dropbox: Selective Sync settings can exclude .DS_Store via patterns (limited support)
  • Google Drive: Use a .gdriveignore file in some clients
  • OneDrive: Limited ignore support

Option 2: Use a shell script that runs periodically to clean cloud folders:

find ~/Dropbox -name ".DS_Store" -delete 2>/dev/null
find ~/Google\ Drive -name ".DS_Store" -delete 2>/dev/null
find ~/OneDrive -name ".DS_Store" -delete 2>/dev/null

Save as ~/clean-cloud-dsstore.sh, make executable with chmod +x ~/clean-cloud-dsstore.sh, run as needed.

Option 3: Add a launchd job to clean automatically (advanced).

Skip the manual huntSweep finds the largest, oldest, most-forgotten files in seconds. Download Sweep free →

Preventing creation in Git repositories

Adding .DS_Store to your global gitignore handles this for all your repositories:

git config --global core.excludesfile ~/.gitignore_global
echo ".DS_Store" >> ~/.gitignore_global
echo "._*" >> ~/.gitignore_global

Now Git ignores .DS_Store and AppleDouble files in every repository. They won’t be added by git add and won’t show in git status.

If they’ve already been committed:

git rm --cached -r .
git add .
git commit -m "Apply gitignore"

That removes tracked .DS_Store files from Git’s index without deleting them locally, then re-adds everything (now respecting gitignore).

Cleaning .DS_Store from existing zips

If you’ve already created zip archives that contain .DS_Store:

zip -d archive.zip "*.DS_Store"

That removes .DS_Store entries from the existing zip without re-creating it. Run for each archive you need to clean.

For Mac-specific archive cleanup (also removes ._AppleDouble):

zip -d archive.zip "*.DS_Store" "*.__MACOSX/*"

The __MACOSX folder is something Apple’s archiving tools sometimes inject. Removing it makes archives cleaner for non-Mac users.

The relationship between .DS_Store and ._ files

Quick explainer of related Mac metadata files.

.DS_Store — Created in every folder Finder views. Contains Finder display state. Just one per folder.

._filename — AppleDouble files. Created when Mac files are stored on non-HFS/APFS filesystems (FAT32, exFAT, network shares). One per data file. Contains extended attributes and resource forks.

.fseventsd — Folder created at the root of mounted volumes. Used by macOS for filesystem event tracking.

.Spotlight-V100 — Spotlight’s index for that volume.

.Trashes — Trash for that volume.

All are hidden by default. Cleaning .DS_Store doesn’t touch the others. To clean ._files specifically:

find ~ -name "._*" -delete 2>/dev/null

Be more cautious — some legitimate files start with underscore patterns.

There’s a faster waySmart Folders work but take setup. Sweep does the same hunt instantly. Try Sweep free →

Why .DS_Store exists at all

Apple’s reasoning: Finder needs somewhere to store per-folder display preferences. The window where you customized icon view with 96px icons should remember that. The folder where you set sort by size should keep that.

Storing this metadata in the folder itself means it stays with the folder if it moves, syncs to other Macs, etc. The alternative would be a central database, which is harder to keep consistent.

The downside is exactly what you’ve experienced — the files leak into places they shouldn’t.

Aggressive prevention

For people who want to stop .DS_Store creation everywhere (not just network/USB):

There’s no official setting for this. Some hacky approaches exist (replacing the .DS_Store file with a folder of the same name to prevent creation) but they break Finder behavior.

The realistic answer: live with .DS_Store on local drives, prevent on network/USB, and clean projects before sharing. .DS_Store on your own Mac is harmless.

Building it into a workflow

For people who package and ship folders regularly (designers, developers, anyone exporting projects), a quick alias helps:

In your shell config (~/.zshrc or ~/.bash_profile), add:

alias cleands='find . -name ".DS_Store" -delete 2>/dev/null'

Then in any folder, cleands removes .DS_Store from the current directory and below. Run before zipping or sharing.

Or for a more aggressive global cleanup:

alias deepclean='find ~ -name ".DS_Store" -delete 2>/dev/null && find ~ -name "._*" -delete 2>/dev/null'

Removes both .DS_Store and AppleDouble files everywhere in your home folder.

A note on storage impact

Disk-space-wise, .DS_Store files don’t matter. 50,000 files × 10KB = 500MB. Maybe 0.1% of your storage on a typical Mac.

The reasons to clean them are all about cleanliness and interoperability:

  • Cleaner zip archives
  • Cleaner shared folders
  • Cleaner Git repos
  • Cleaner USB drives sent to colleagues

Storage gain is incidental. Don’t expect a noticeable improvement in free space — but you’ll stop annoying every non-Mac user who receives your files.

A cleaning tool can include .DS_Store removal as part of a broader sweep. Combined with the prevention settings for network and USB shares, you can mostly forget about .DS_Store except when actively packaging something for distribution.

← Back to all guides