Delete All .DS_Store Files from Mac OS X
In this article
Yes, you can delete all .DS_Store files from your Mac, and doing so is safe—they are automatically regenerated by Finder as needed. These hidden files store folder view preferences (icon size, window position, sort order) and appear in almost every folder you browse. Deleting them won't harm your data, but it will reset the custom view settings for those folders.
What Are .DS_Store Files?
.DS_Store (short for Desktop Services Store) is a hidden file created by the macOS Finder application. It was introduced in Mac OS X 10.0 and replaced the older Desktop DB and Desktop DF files. Each time you open a folder, Finder may create or update a .DS_Store file inside that folder to remember how you like to view its contents—whether as icons, list, columns, or gallery, along with sorting order, window size, and icon positions.
These files are invisible by default in Finder, but you can see them in Terminal with ls -la. They are also often copied to external drives, network shares, or zip archives, which can clutter shared repositories or confuse users on other operating systems (like Windows) who see these odd files appear.
Why You Might Want to Delete Them
There are several common reasons to remove .DS_Store files:
- Cleaning up shared folders: If you copy a folder to a Windows PC or a Linux server, the .DS_Store files are useless and can be considered clutter.
- Fixing display issues: Occasionally, a corrupted .DS_Store can cause a folder to show wrong icons, wrong sort order, or even crash Finder. Deleting it forces Finder to rebuild the file from scratch.
- Privacy: .DS_Store files can reveal folder names and paths you may not want to share if you accidentally send them to someone.
- Reducing backup size: If you back up a huge directory tree, thousands of tiny .DS_Store files can slightly inflate the backup and slow down syncing.
How to Delete All .DS_Store Files
The most direct way is using Terminal. Open Terminal (from Applications/Utilities or Spotlight) and run one of these commands:
- Delete all .DS_Store files in your home directory:
find ~ -name ".DS_Store" -delete - Delete all .DS_Store files on your entire startup disk:
sudo find / -name ".DS_Store" -delete(you'll be prompted for your password) - Delete them only in the current folder and subfolders:
find . -name ".DS_Store" -delete
The find command searches recursively. The -delete flag removes each file as it's found. Using sudo gives permission to delete files in protected system areas, but be careful—you don't need to delete them from system folders like /System or /Library; they rarely appear there. Running the command without sudo on your home folder is usually sufficient.
What Happens After Deletion?
After you delete .DS_Store files, Finder will recreate them the next time you open a folder. This means your custom view settings (like icon size or sort order) will be reset to the default for each folder. You'll need to re-apply any special settings you had. The files are tiny (usually a few KB), so you won't notice any performance change. The deletion is immediate and permanent—there's no Trash for these files, so make sure you really want to remove them.
How to Prevent .DS_Store Files from Being Created
You can't stop Finder from creating .DS_Store files on your local disk—it's part of how Finder works. However, you can prevent them from being written to network volumes and external drives. Run this command in Terminal:
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
This tells Finder not to create .DS_Store files on network shares (like SMB or AFP). To also block them on external drives (like USB sticks), you can use a similar setting, but it's not officially supported. One workaround is to use a tool like dot_clean or a third-party app, but the simplest is to just delete them after copying.
Common Problems and Misconceptions
Misconception: .DS_Store files are viruses or malware. They are not. They are plain metadata files. However, they can be used to hide malicious code if an attacker plants a specially crafted .DS_Store, but that's extremely rare.
Problem: You can't see them in Finder. By default, Finder hides all files starting with a dot. To see them, open Terminal and use ls -la, or press Cmd+Shift+. in Finder to toggle hidden files (works in macOS 10.12 and later).
Problem: Deleting .DS_Store files doesn't fix a folder that still looks wrong. If the issue persists, the problem might be with Finder's preferences or a corrupted icon cache. Try restarting Finder (hold Option, right-click Finder icon in Dock, select Relaunch) or resetting the icon services database.
Alternatives to Manual Deletion
If you need to clean .DS_Store files regularly, you can automate it with a cron job or a launch agent, but that's overkill for most users. A simpler alternative is to use the dot_clean command, which merges .DS_Store files on a volume, but it doesn't delete them. For a one-time cleanup, the find command is the best tool. Some developers add a .gitignore entry for .DS_Store to keep them out of version control repositories, which is a good practice if you share code.
Frequently Asked Questions
Is it safe to delete all .DS_Store files?
Yes, it is completely safe. They are just preference files for Finder. Deleting them will only reset folder view settings; your actual files and data are untouched.
Will .DS_Store files come back after I delete them?
Yes, Finder recreates them automatically whenever you open a folder. So if you delete them, you'll see new ones appear over time. That's normal.
Can I delete .DS_Store files on a Windows PC?
Yes, you can delete them on Windows using File Explorer or Command Prompt. They are just regular files. However, if you're cleaning a shared drive, it's better to delete them from a Mac using the Terminal command to ensure all are removed.
Why do .DS_Store files show up on my USB drive?
When you plug a USB drive into a Mac and open it, Finder may create a .DS_Store file on that drive to remember how you view it. To prevent this, you can use the defaults command mentioned earlier, or simply delete them after use.
Does deleting .DS_Store files speed up my Mac?
No, not noticeably. These files are tiny and few in number. They don't consume significant disk space or slow down your system. The only benefit is cleanliness and avoiding clutter on shared drives.