If you use a Mac and frequently share ZIP files with Windows users, or if you regularly upload projects to a Git repository, you are undoubtedly familiar with the infamous .DS_Store file. macOS automatically generates these invisible “Desktop Services Store” files inside every single folder you open. They store custom metadata for the Finder, such as window sizes, icon positions, and background colors.
While harmless on a Mac, these files look like annoying junk data when viewed on a Windows machine. Furthermore, committing them to a public code repository is a classic rookie mistake that clutters the commit history. To properly clean your directories before sharing them, you must learn how to view and systematically delete these hidden files using the macOS Terminal.
Step 1: View Hidden Files in Finder
By default, macOS hides any file that begins with a period (dot) to prevent users from accidentally deleting critical system files.
To reveal them instantly:
- Open the Finder application.
- Navigate to the folder you want to inspect.
- Press Cmd + Shift + Period (.) simultaneously on your keyboard.
Your screen will refresh, and you will suddenly see faded, translucent icons appear. Among them will be the ubiquitous .DS_Store file. You can right-click and delete this file manually, but if you have a complex project with dozens of subfolders, deleting them by hand is a waste of time.
Step 2: Delete All .DS_Store Files Using Terminal
To purge every single .DS_Store file from a master folder and all of its nested subdirectories simultaneously, we will use a powerful UNIX command called find.
- Open the Terminal app (found in Applications > Utilities).
- You need to navigate to your master folder. Type
cdfollowed by a space, then drag and drop the folder from Finder directly into the Terminal window. The Terminal will automatically write out the path for you. Press Return. - Now that you are inside the correct directory, paste the following command exactly as written:
find . -name '.DS_Store' -type f -delete - Press Return.
How the command works:
find .instructs the system to search the current directory and every folder beneath it.-name '.DS_Store'tells it to specifically look for files with that exact name.-type fensures it only targets files, not directories.-deleteforcefully erases them without asking for confirmation.
The command executes silently. When the terminal prompt returns, your entire directory tree is completely clean and ready to be zipped or committed to Git.
Bonus: Stop macOS from Creating .DS_Store on Network Drives
If you connect to a shared Windows server or a NAS, macOS will ruthlessly spam .DS_Store files all over the network, annoying your PC colleagues.
You can force macOS to stop writing these files to external network drives by pasting this command into the Terminal:
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
Press Return, then restart your Mac to apply the global change.