prostuff1 Posted September 29, 2009 Share Posted September 29, 2009 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. #!/bin/bash # 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. Quote Link to comment
btlupin Posted September 29, 2009 Share Posted September 29, 2009 I can recommend an app called BlueHarvast that takes care of this problem as you move your files or folders. I have used it a couple of years now, since I had trouble with SABnzbd not starting if the queue folder contains .ds files. Quote Link to comment
cwr Posted September 29, 2009 Share Posted September 29, 2009 defaults write com.apple.desktopservices DSDontWriteNetworkStores true type that into terminal and you should be good to go. no more DS_Store files Quote Link to comment
prostuff1 Posted September 29, 2009 Author Share Posted September 29, 2009 defaults write com.apple.desktopservices 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. Quote Link to comment
ClunkClunk Posted September 29, 2009 Share Posted September 29, 2009 ._ 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. Quote Link to comment
prostuff1 Posted September 29, 2009 Author Share Posted September 29, 2009 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. Quote Link to comment
ClunkClunk Posted September 29, 2009 Share Posted September 29, 2009 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. Quote Link to comment
RobJ Posted September 29, 2009 Share Posted September 29, 2009 Added to the FAQ (link back only), What do Mac users do with the Mac hidden files?. Feel free to edit or expand. If someone has a better idea for the wording of the question that would be more acceptable to Mac users, please let me know or feel free to change it yourself. Edit: would "What should Mac users do with those Mac hidden files?" be better? Quote Link to comment
ClunkClunk Posted September 30, 2009 Share Posted September 30, 2009 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 macosxhints.com: You can see if a file "foo" has a resource fork via the command: ls -l foo/..namedfork/rsrc Quote Link to comment
cbr600ds2 Posted August 5, 2011 Share Posted August 5, 2011 You just type that line onto terminal once and it will not create those files from then on? Quote Link to comment
defected07 Posted August 5, 2011 Share Posted August 5, 2011 No, there is a package you can install from unMenu. It'll add the script to a cron job so it'll run daily, early AM. Quote Link to comment
Brian B. Posted February 18, 2015 Share Posted February 18, 2015 Any chance anyone wants to make this into a quick plugin for Unraid 6? Quote Link to comment
voldak Posted January 4, 2016 Share Posted January 4, 2016 Has anyone got this working on Unraid 6? If so, what was the fix? Quote Link to comment
wgstarks Posted January 13, 2016 Share Posted January 13, 2016 Run it as a cron job. Quote Link to comment
kizer Posted January 13, 2016 Share Posted January 13, 2016 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. Quote Link to comment
John_M Posted January 14, 2016 Share Posted January 14, 2016 Under SMB Settings there's an option to hide "dot" files. Would that help preserve Windows users' sanity? Quote Link to comment
kizer Posted January 14, 2016 Share Posted January 14, 2016 Yes 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. Quote Link to comment
JonathanM Posted January 14, 2016 Share Posted January 14, 2016 Yes 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. Quote Link to comment
mrow Posted January 20, 2016 Share Posted January 20, 2016 I personally use Blue Harvest for this purpose. Instead of deleting these files after the fact it prevents them from being created in the first place. http://www.zeroonetwenty.com/blueharvest/ It's not free but a single $15 license covers up to three Macs. It has the added bonus of preventing these files from being created on USB connected drives as well. Quote Link to comment
Recommended Posts
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.