-
Notifications
You must be signed in to change notification settings - Fork 27
Banishing DS_Store, Thumbs.db, and other pesky files we don't need
DS_Store files are automatically created in Macs by the operating system to store Finder visibility information (the way icons are displayed). The name stands for "Desktop Services Store". They're generally set to be invisible, so you don't "see" them in your Finder, and they're usually harmless, except when we're working on processing a collection of files with XSLT or XQuery, or when Mac users inadvertently pass their DS_Store files into a shared GitHub repo and on to their teammates on any computer (Windows, Mac, or Linux). (If you're a Windows user and you see a DS_Store in your file directories, it's because you've imported them from a teammate's Mac.) Deleting them causes no problems either, and is necessary sometimes to debug a process, especially when we've written XSLT to process a file directory. A thumbs.db file is similar: it's created to control the display of files as icons. Thumbs.db can cause similar problems as DS_Store because it interferes when we attempt to access and process a collection of files--it introduces processing problems because its content isn't consistent with the other files in your directory.
Banishing these files is typically only temporary. We can clean them off of our systems, but usually we trigger their return, just by using our computers.
- It helps to see your hidden files:
- On a Mac, here are some ways to set that up from your Terminal
- On a PC, here's how to view thumbs.db and prevent its recurring, through the Windows File Explorer
- To delete them, temporarily, on a Mac:
- On a Mac, use your Terminal, and copy and paste in the command below exactly (using command + v to paste). (IMPORTANT: Don't try to type this by hand; you might miss something and delete all your files and directories!)
sudo find / -name ".DS_Store" -depth -exec rm {} \;
Because you're using sudo
to take command and change the default settings on your computer, you'll be prompted to enter your user name and password that you use to access your Mac.
Note: This command might take a minute or two to complete: It's purging each of your file directories of .DS_Store
files.
- On a Mac, this purge (in step 2) is only going to be temporary: The next time you restart your Mac, you'll likely trigger the generation of new .DS_Store files. If you'd like to do a housecleaning process periodically, like every day, we recommend setting up a "cron job", that is, create a little program that runs at a regular time each day (or overnight) while your computer is powered on, that runs the script we just ran. (We learned this from Adobe, and are expanding their explanation here.). This is a little tricky and uses a special text editor called "vi" associated with your Mac Terminal (It's tricky b/c the vi editor responds only to keystrokes, not to mouse clicks.) Follow these instructions to navigate and enter (and adjust) what you need:
In your Terminal, paste in the following (using command + v):
sudo crontab -e
(Enter your password for sudo, as we did above). The vi editor will open and you'll see the default "crontab" holding chronic processes. You'll be adding one.
Type the capital letter "I". (Typing I lets you make an insertion in the vi editor).
**Paste in the following line, but let's read it first and see if you want to make a time adjustment:
15 1 * * * root find / -name ".DS_Store" -depth -exec rm {} \;
Here's how the crontab is formatted: The first five entries indicate timing:
Minute Hour DayOfMonth Month DayOfWeek UserCommand.
Note: Our sample command above is set to run our crontab regularly at 1:15 AM everyday, and the asterisk (*) on the other time entries means we aren't setting a specific monthly date or day of the week to run it because we want this to process every day. To configure the command for a different time, set your own values as you prefer, and keep in mind that your crontab won't run if your computer is powered off.
- Now, to save and exit the vi editor, press Esc, then hold down simultaneously Shift Z Z.
We create a special hidden file called simply .gitignore
, which is just a specially-named text file that lists file types we don't want to be tracked, committed, or shared with others in a GitHub directory. Create one of these in a text editor, save as .gitignore
, and commit and push it to the top level of each of your GitHub repositories, and this will prevent DS_Store and thumbs.db (and their kin) from ever being shared, even if your local computers are creating the files. Here is a useful sample .gitignore
that we used as the basis for our own gitignore on this repo. Here is our own .gitignore
for the DHClass-Hub.
To read more about .gitignore
files, and how to configure a global gitignore to help control all your repos, see GitHub's article on "Ignoring Files".