How to View and Delete the Hidden ‘.DS_Store’ Files on a Mac Using Terminal

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:

  1. Open the Finder application.
  2. Navigate to the folder you want to inspect.
  3. 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.

  1. Open the Terminal app (found in Applications > Utilities).
  2. You need to navigate to your master folder. Type cd followed 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.
  3. Now that you are inside the correct directory, paste the following command exactly as written:
    find . -name '.DS_Store' -type f -delete
  4. 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 f ensures it only targets files, not directories.
  • -delete forcefully 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.

RELATED POSTS

  • How to Reset Launchpad Layout to Default in macOS
  • How to Use Time Machine to Backup and Restore Your Mac
  • How to set MAC address in Windows using Device Manager?
  • How to Force Restart an Unresponsive Mac
  • How to Completely Remove an Application from Your Mac
  • Get the best tech tips delivered straight to your inbox.

    Join thousands of readers mastering Apple, Google, Microsoft, and Linux.