Automatically Remove Those Pesky .DS_Store Files

If you have your hidden files shown, pesky .DS_Files pop up everywhere. Remove .DS_Store files automatically with this simple command.
Published
Updated
Typical Read
2 minutes
Sponsored
Sponsor my site by donating to help support open-source projects, like WordPress Zero Spam, Referrer Analytics & others.
Find your next web developer job
jobs by Indeed

Automatically Remove Those Pesky .DS_Store Files was originally published on Jan 4, 2015 and has recently been updated on Aug 6, 2020 to reflect emerging trends.

If you’re a developer on a Mac, you most likely have hidden files set to show like .htaccess and .profile. That’s when those pesky .DS_Store files start popping up in every directory. If you’re a little OCD like me, they can drive you crazy. Here’s a few simple commands you can run in Terminal to have those files removed.

.DS_Store files are automatically created by Mac OSX Finder in browsed directories. These files contain information about system configuration. If you upload them along with other files, the files can be misused to obtain information about your computer. For more information, see Apple security updates.

How to Remove All .DS_Store Files

  1. Select Applications > Utilities to launch Terminal.
  2. Enter the following UNIX command:
    sudo find / -name ".DS_Store" -depth -exec rm {} \;
  3. When prompted for a password enter your Mac OS X Administrator password.

Automatically Remove .DS_Store Files Periodically

  1. Select Applications > Utilities to launch Terminal.
  2. Enter the following UNIX command:
    sudo crontab -e
  3. When prompted for a password enter your Mac OS X Administrator password.
  4. In the vi editor, press the letter I on your keyboard once and enter the following command:
    15 1 * * * root find / -name ".DS_Store" -depth -exec rm {} \;

    This crontab entry has the following format:

    <Minute> <Hour> <DayOfMonth> <Month> <DayOfWeek> <User Command>.

    The system automatically runs the command at 1:15 AM everyday. To configure the command for a different time, use different values.

    Note: This command is not run if your computer is switched off at the scheduled time.

    To save the entry press the Esc key once, then simultaneously press Shift+z+z.


Additional Information

For more details, see Mac OS X Hidden Files & Directories.

Did you find Automatically Remove Those Pesky .DS_Store Files useful? Get articles in your inbox.

…and don’t worry, I hate spam as much as you. Expect to hear from me at most once a week.

Latest Job Postings
Posted on Aug 9, 2020 at 9:17pm
Full-time
Los Angeles
Posted on Aug 9, 2020 at 9:15pm
Full-time
Los Angeles
Posted on Aug 8, 2020 at 4:57pm
Full-time
Los Angeles
Sponsored
Do you have a great article to share you want to contribute? Contact me about your idea.
Sponsored
Help support open-source projects & pro-bono non-profit services by donating today.
Sponsored
Need help with website, a boost in ranking or online marketing? Contact me today for a free quote.
Sponsored
Do you run a development agency, freelance developer or offer website services. Contact me today for information about advertising.
Sponsored
Do you run a development agency, freelance developer or offer website services. Contact me today for information about advertising.

Leave a Reply

Your email address will not be published. Required fields are marked *

All comments posted on 'Automatically Remove Those Pesky .DS_Store Files' are held for moderation and only published when on topic and not rude. Get a gold star if you actually read & follow these rules.

You may write comments in Markdown. This is the best way to post any code, inline like `<div>this</div>` or multiline blocks within triple backtick fences (```) with double new lines before and after.

Want to tell me something privately, like pointing out a typo or stuff like that? Contact Me.