Refer: https://www.tekrevue.com/tip/stop-ds-store-files-mac-network/
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool TRUE
macOS creates a .DS_Store file in every folder you view in Finder. This file stores metadata about that folder’s contents as well as user customizations for things like view type and icon size.
These .DS_Store files are hidden from you in macOS so they won’t clutter up your folder views. But in mixed-OS environments, the .DS_Store files can become a problem. That’s because your Mac creates these files even for shared network locations. So if you’re sharing a NAS at your office with people using Windows PCs, they may suddenly see a bunch of .DS_Store files littering the shared directories (at least, depending on how the Windows users have their view preferences configuredin File Explorer).
A Mac’s .DS_Store file visible in Windows.
You can manually delete .DS_Store files without losing any data. The only issue is that when you next browse to a shared folder after deleting its .DS_Store file, Finder will revert to the default layout and won’t remember any custom view types or font sizes you may have set. This approach, however, requires you to manually delete these files each time they pop up (and macOS will create a new replacement file each time you return to the shared directory). Instead, you can configure macOS to not create .DS_Store files on network shares in the first place.
Stop Creating .DS_Store Files
To configure your Mac to not create .DS_Store files on shared network drives, log into macOS, launch the Terminal, and enter the following command:
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool TRUE
Once you’ve executed the command, save any open work and log out of your macOS user account. When you log back in, reconnect to your shared network drives. Existing .DS_Store files may still be present and will need to be manually deleted, but your Mac won’t create any new .DS_Store files as you browse the shared directories going forward.
