What a .DS_Store file holds
The Finder writes a hidden file named .DS_Store into folders you open or rearrange. It records how that folder’s window should look: icon or list view, sort order, column widths, icon positions and a background picture if you set one. Apple’s note on network browsing describes the Finder gathering labels, tags and other metadata to decide how each window and its contents appear; .DS_Store files are where the per-folder layout is kept.
Your documents don’t depend on it. On Mac-formatted disks, tags and other file metadata are stored with each file, so removing a .DS_Store doesn’t strip tags or change any file. You can see the files in Finder with Shift-Command-Period, or in Terminal with ls -la.
What happens when you delete one
The folder forgets its custom layout. Next time you open it, the Finder uses your default view options and writes a fresh .DS_Store as soon as it has something to remember. If you deleted it while the folder was open, the Finder may simply write it back. Apart from the window layout, nothing is lost.
That makes deleting them pointless as a space cleanup. There are good reasons to remove them anyway: before zipping a folder for someone on Windows or Linux, before copying files to a device that shows hidden files, or when they have slipped into a code repository. The first command below lists them under a folder and only reads. The second moves them to the Trash with the trash command in macOS 15 and later. Change ~/Projects to the folder you mean; run across your whole home folder, it would reset every custom Finder layout there.
find ~/Projects -name .DS_Store -type f
find ~/Projects -name .DS_Store -type f -exec trash {} +USB drives and memory cards
Apple doesn’t document an equivalent setting for USB drives. You’ll find one quoted online, but this guide sticks to settings Apple supports. On removable drives, .DS_Store is one of several hidden items macOS writes, alongside Spotlight, event-log and Trash folders, and ._ files on drives formatted for Windows.
The guide to hidden files on USB drives covers what each of those is and how to reduce them: exclude the drive from Spotlight, empty the Trash before ejecting, clean up ._ files with dot_clean, and eject properly.
Keep .DS_Store out of Git
Git reads a global ignore file for patterns you never want in any repository. On most Macs its default location is ~/.config/git/ignore, so the two commands below create the folder if needed and add .DS_Store to that file. If you have pointed core.excludesFile at a different file, add the line there instead; git config --global core.excludesFile shows the setting.
Ignoring affects only files Git isn’t already tracking. If a .DS_Store was committed earlier, remove it from the index with git rm --cached and the file’s path, then commit; the file stays on disk and Git stops tracking it. Adding the pattern to a project’s own .gitignore also helps collaborators who haven’t set up a global file.
mkdir -p ~/.config/git
echo .DS_Store >> ~/.config/git/ignoreCommon questions
Is it safe to delete .DS_Store files on Mac?
Yes, deleting a .DS_Store file is safe because it only stores how Finder displays that folder, such as view style, sort order and icon positions. The folder's window goes back to your default view, and Finder writes a new file the next time it needs one, so no documents or tags are affected.
Why does .DS_Store keep coming back after I delete it?
Finder writes a fresh .DS_Store as soon as it has something to remember about that folder's layout, and if you deleted it while the folder was open, Finder may simply write it back right away. This makes deleting them for space pointless, since they're only a few kilobytes each.
How do I stop .DS_Store files from appearing on network shares?
Apple documents a setting for SMB file shares that turns off .DS_Store there, after which you log out and back in for it to take effect. The trade-off is that Finder no longer remembers custom view settings for folders on that share.
How do I keep .DS_Store out of a Git repository?
Add .DS_Store to Git's global ignore file, usually at ~/.config/git/ignore, which keeps it out of every repository you haven't already committed it to. If a .DS_Store was committed earlier, remove it from the index with git rm --cached and commit, which stops tracking it without deleting the file from disk.
References & further reading
These guides combine the linked official guidance with ClearDisk’s documented behavior. Your files and app settings determine the right next step.