Skip to main content

Command Palette

Search for a command to run...

.DS_Store Nuisance

Published
3 min read
.DS_Store Nuisance

Introduction

.DS_Store files on macOS are used by the Finder to store custom attributes and metadata for folders, such as icon positions, view settings, and other visual information. These files are hidden by default in the Finder and many Unix utilities. They are automatically created when you view a folder in Finder and are associated with that folder, even when archived or moved.

Extra Details

  • Purpose:

    .DS_Store files store information about how a folder should be displayed in Finder. This includes things like icon layout, window size and position, and sort order.

  • Creation and Persistence:

    These files are created automatically by the Finder when you view a folder. They are also copied when you copy or compress a folder.

  • Visibility:

    .DS_Store files are hidden by default on macOS. They are also often visible on Windows machines when a Mac user shares files or uses external drives formatted with FAT32 or exFAT.

  • Potential Issues:

    While generally harmless, .DS_Store files can be problematic in certain situations, such as when sharing files with other operating systems or when dealing with version control systems like Git.

  • Forensic Relevance:

    In some cases, .DS_Store files can be useful for forensic analysis, as they can provide information about which folders have been accessed and how they were viewed.

  • Disabling Creation:

    It is possible to disable the creation of .DS_Store files on network drives or for specific folders.

How To Handle .DS_Store Files

  1. Disable .DS_Store creation on network shares:

    • Open Terminal.
    • Enter the command: defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool TRUE.
    • Press Return.
    • Reboot your Mac.
    • To re-enable, use defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool FALSE and reboot, according to TechRepublic.
  2. Remove existing .DS_Store files:

    • From the command line:
      • To remove all .DS_Store files in the current directory and subdirectories: find . -name ".DS_Store" -delete or find . -name ".DS_Store" -type f -delete.
      • To remove all .DS_Store files in the entire file system (use with caution): sudo find / -name ".DS_Store" -depth -exec rm {} \;.
    • Using tools:
      • Some third-party tools like Blue Harvest can help manage or remove these files.
  3. Ignore .DS_Store files in Git:

    • Create a .gitignore file in your repository (if one doesn't exist).
    • Add .DS_Store to the .gitignore file.
    • Commit and push the changes.
  4. Periodically remove .DS_Store files:

    • Use a cron job to automate removal:
      • Open Terminal and run sudo crontab -e.
      • Enter your password when prompted.
      • Add the following line (to run daily at 1:15 AM): 15 1 * * * root find / -name ".DS_Store" -depth -exec rm {} \;.
      • Press Esc, then Shift+Z+Z to save.
      • Adjust the time as needed.

Conclusion

While harmless in themselves, they can be a nuisance in version control systems like Git and pose potential security risks if exposed on web servers. They can be safely ignored or removed from Git repositories and web servers to prevent issues using any the methods we explored in this article.

More from this blog

Cloud Tuned

629 posts

Your starting point for anything cloud: AWS, Azure, GCP, Serverless, Architecture, Hybrid Cloud, Systems Design and other Information Technology topics.