And… we’re back!

I’m working on a couple interesting things that I’ll be sharing shortly.
In the interim, here’s a quick little tidbit!

Do you have a datastore (NAS, File Server, etc?) Of course you do! Everyone needs a solid reliable place to store media, music, ISOs, user files, and Virtual Machines! Do you also happen to have at least one OSX client? Then you’re already painfully aware that OSX tends to create hidden files when it accesses and writes to network shares. There are two basic methods for getting rid of these files from your datastore.

1) Tell OSX to stop creating .AppleDouble files on network shares.

  • Open Terminal and type the following…
  • defaults write com.apple.desktopservices DSDontWriteNetworkStores true
  • Reboot or Log Off.

2) Create a simple shell script to search and remove them.

  • Open a text editor (TextEdit, TextWrangler, Notepad, etc) and create a new plain text file.
  • Place the two lines below in the file and save it as “clean-osx-hidden-files.sh” (or whatever you want, but make sure it ends with “.sh”
  • find / -name ".DS_Store" -depth -exec rm {} \;
    find / -name ".AppleDouble" -depth -exec rm -Rf {} \;
  • Now save the file to your datastore and ensure that “root” owns the files and has correct permission to run it.
  • In my case, I use a Synology DS-1512+ as my primary datastore and saved the file at /volume1/public/clean-osx-hidden-files.sh
  • Log into DSM and go to Control Panel > Task Scheduler
  • Create a User-Defined Script task
  • Give the task a name. (It can be anything you want.)
  • Assign a user account to be used to execute the script. This account must have access to the entire volume else it may miss files.
  • For the task to run input the path and name of the script. In my case this would be, “/volume1/public/clean-osx-hidden-files.sh”
  • Then assign it a frequency to run. Personally, I have mine set to run daily, but you may want it to prune more frequently depending upon how often you get the files cropping up.
  • Save it and you should be done!DSM Cron Job

Now for a word of caution: Make sure access to the location of the script file is secure. I cannot emphasize this enough! If the location is not restricted to authorized someone could very easily modify the script to do, well… anything! In my example, the directory may be called “public” but access is restricted to everyone except the local admin account and the Enterprise Admins group. Since this is a home network and there’s just two of us here I’m not too worried. So, do as I command! 🙂

Notes: Making OSX stop creating them is the ideal solution. However, the Terminal command only prevents creation of .AppleDouble file,  is not 100%, and is on a per-user basis (unless you modify the default .plist file which is another matter.)

The Task Scheduler in the Synology DiskStation is really just a front-end for cron. The exact same script and basic procedure applies to other Linux variants. So you can adapt the procedure to work with devices other than the DiskStation with a small amount of modification.

Happy pruning! Get ready for fun with VLANs, iSCSI, vSphere, vSwitches, and more coming up soon!