For the Mac users out there

Recommended Posts

As a lot of Mac users know when we copy files to a SMB share there are usually some tag alongs that are not visible to us but are to the Windows people.  The files usually begin with . or ._ and pretty much serve no purpose at all; most of the stuff is related to resource forks that are no longer in use except by some font files and other misc things.  Anyway, I got tired of these being on my server so I went and made a little script that will remove all the .DS_Store files and all the files beginning with ._.


This works just fine for me and I have it so that this is run when the server is restarted, but it would probably be best used if made into a cron task that could be run every hour, day, whatever.


Just copy and past the code into a file and you are all set to go.


# Version .1 - remove .DS_Store files and ._* files

# ========================================================================== #
# Program Body                                                               #
# ========================================================================== #
echo "Removing .DS_Store files"
find /mnt/ -name .DS_Store -delete
echo "======================="
echo "Removing ._ files"
find /mnt/ -name ._* -exec rm '{}' \; -print


NOTE: For the Mac users that want to not end up with .DS_Store files being created on network shares see this apple article on how to prevent it.  This will not stop .DS_Store files in folders currently from being moved with the rest of the data to the drive but it will stop OS X from creating them in the first place on a network share.

Link to comment

defaults write DSDontWriteNetworkStores true


type that into terminal and you should be good to go. no more DS_Store files


You are correct, that will prevent the creation of the files if you are browsing a share and/or making changes somehow.  If the .DS_Store files already exist in a folder and you copy it over to the network it will NOT be removed by using this command; hence the applescript above.


As for Blueharvest: I like what the program does and I did come across it when I was doing my searching but I do not want to pay for something that I can do for free.  The only thing I really need to do is to get this into a cron job so that it runs like every hour or so.  If anyone has opinion on how often it should run via cron let me know and I will try to get it put into a cron job soon.

Link to comment

._ files (HFS+ resource forks) can also be removed via the Mac OS X command "dot_clean /Volumes/VolumeName"


But I have to say, I like prostuff1's method better. I'm thinking I may have it run as a cron job once every 4 to 6 hours. It really doesn't matter how often it runs, as long as it's cleaning up the ._ and .DS_Store as they're created, so that means either as you copy files to the server that have resource forks (._) or as you change window positions/settings with the Finder (.DS_Store).


Just be careful removing ._ files. Very few Mac OS X files still use resource forks for more than type/creator codes, but a few legacy items may still need the resource fork.

Link to comment

Just be careful removing ._ files. Very few Mac OS X files still use resource forks for more than type/creator codes, but a few legacy items may still need the resource fork.


I came across this same information but it was incredibly hard to find what kind of files actually use the ._ stuff constantly.  From my research the ._ is mostly a hold over from the Mac OS 9 days and is rarely used but you can read up on it here.


Once I get a chance to make a cron task out of this script it will be immensely more useful... I just need to find the time to read up on cron a little before doing it.

Link to comment

It mostly is a holdover from OS 9 days. Resource forks were were certain types of data existed. With the transition to OS X, and in particular, carbon programs that could run on both OS 9 and OS X, a few programs used resource forks even deep in to OS X's development.


With that said though, I would surmise that the vast majority of the ._ resource forks are something simplistic, like type/creator codes (which OS X has other ways of interpreting - file extensions in particular), and not large chunks of data.

Link to comment

I did a little more research on the ._ (dot underscore, resource forks), just so we have complete information. It looks like they're nearly deprecated by modern Extended File Attributes in Mac OS X 10.4 and greater. However a few programs (I noticed reports of Excel and Quicken) still use resource forks to store some important data. Other files just store it for compatibility, and it's inconsequential or data that's duplicated in the Extended File Attributes. Removal of these files shouldn't cause problems as the vast majority of OS X files store their data purely in the data fork, however test your files carefully.


.DS_Store is what keeps track of icon and window positions. It's a replacement for the old monolithic Desktop DB and Desktop DF files from the classic Mac OS days (remember rebuilding the Desktop? Those are what were rebuilt). It also is related to things like Finder Get Info comments.


Some other info:

BlueHarvest is shareware title that can assist with automatic removal of .DS_Store and ._ files. It runs on the Mac directly, not on your server.

• Apple has a knowledgebase article which has information about a terminal command to stop producing .DS_Store files on network volumes. It does not affect ._ files. It states it's for Mac OS X 10.4, however there were mentions on various sites that it works fine in 10.5 (and possibly 10.6?)

• From a post on

You can see if a file "foo" has a resource fork via the command:
ls -l foo/..namedfork/rsrc

Link to comment
  • 1 year later...
  • 3 years later...
  • 10 months later...
  • 2 weeks later...

I get a bunch of those annoying files when I backup my photos to to my server. When I browse them on my windows machine it drives me literally insane. I just amended the line to point out specifically where I want them cleared.


find /mnt/disk4/Photos/ -name "._*" -print -delete

find /mnt/disk4/Photos/ -name ".DS_Store" -print -delete


You can cron them, but I just run a script once a month when I backup some photos. I just like to tell it exactly where to look opposed to letting it scour my entire server.

Link to comment


Under SMB Settings there's an option to hide "dot" files. Would that help preserve Windows users' sanity?


Yes, but thats kinda like shoving boxes in your closet or under your bed when company comes over. Still have to deal with them later, or eventually. ;)

Or not, just leave 'em for your heirs. Analogy works both virtually and in meatspace.  ;)
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.