Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Automatically delete Mac OS X dot files from MS-DOS filesystems System
I often use a USB flash drive on my Mac that's formatted with an MS-DOS filesystem. I usually copy JPGs and MP3s onto it for use with my household DVD player. When I plug the flash drive into the DVD player's front-panel USB port, I can view the files on my TV. The problem is that the DVD player is very simple and it shows all the dot files that Mac OS X puts on it, like .Trashes and a .DS_Store in almost every folder.

I wanted to prevent Mac OS X from writing those files to MS-DOS filesystems at all, but I couldn't find a way to do that. My second thought was to write an AppleScript that would execute whenever the eject operation was requested, deleting the dot files, but I couldn't find a way to do that, either. So, being an old UNIX guy, I decided to try going down to that level and writing a wrapper script for umount, the program that does a lot of the work when ejecting (or 'unmounting') a filesystem.

This has worked out for me very well, but this solution might not be for everybody. This hint will explain how to install a umount wrapper script, but great care must be taken while doing so. You'll be using Terminal.app, working as the root user, and moving important OS utilities. A mistake in these steps could cause a lot of trouble for you.

To install the wrapper:
  • Run Terminal.app.

  • At the shell prompt in Terminal, run this command to become root:

    sudo -s

    You will be prompted to enter your own password. You must be an Admin user in order to do this.
  • Go to the /sbin directory and move the original umount utility to a different name. Use this command:

    cd /sbin; mv umount umount-orig

  • Put the following script into a file named umount in the /sbin directory. The best way is to paste this into a text editor and save it as umount:
    #!/bin/sh --
    loggerTag='umount-wrapper'
    
    (
      if [ "$@" ]; then
        for i in "$@"; do
          echo $i
        done
    
        fstype=`diskutil info "$1" | sed 's/ //g' | grep '^Type:' | cut -d':' -f2`
    
        echo "fstype is ${fstype}"
    
        if [ "$fstype" = "msdos" ]; then
          echo cleaning msdos filesystem...
          find "$1" -depth -name '.[^.]*' -print -exec /bin/rm -fr {} \;
        else
          echo not msdos, skipping to umount...
        fi
      fi
    ) | logger -st $loggerTag
    
    /sbin/umount-orig "$@"
    
  • Just to make sure things are correct, set the permissions and owners of the umount files:

    chmod 555 /sbin/umount*; chown root:wheel /sbin/umount*

  • You're done! Exit Terminal.app now, just to be safe.
What this script will do is check that the filesystem being ejected is of type 'msdos.' If it is, it will look through all the folders on the filesystem and delete the ones that begin with a dot. (It purposely ignores "." and "..", of course). All output from the script is sent to the system logger, so if you run Console.app, you'll be able to see the output in the system.log. It will show the name of the filesystem being ejected, its type, and if files are being deleted, you'll see their names, too. After the checking and deleting is complete, the script calls the old umount-orig utility to eject the now-clean filesystem.

This may be obvious, but if you intentionally copy dot files (like your .bashrc file) to your MS-DOS filesystem, they will be deleted when you eject the filesystem. A couple possible ways to prevent this would be to put your dot files into a ZIP file or change this script to be more specific about which files it deletes.

In my opinion, Apple should put an option into the OS to not put its special dot files onto MS-DOS filesystems and the option should be enabled by default. Users that then need those dot files can then disable the option.

[crarko adds: I haven't tested this one. Please be careful with this one if you try it. There are a couple of earlier hints that cover similar territory as this one.

Note: Correction made to the script per the author to add the -fr command to the line:
find "$1" -depth -name '.[^.]*' -print -exec /bin/rm -fr {} \;.]
    •    
  • Currently 2.36 / 5
  You rated: 3 / 5 (11 votes cast)
 
[29,602 views]  

Automatically delete Mac OS X dot files from MS-DOS filesystems | 34 comments | Create New Account
Click here to return to the 'Automatically delete Mac OS X dot files from MS-DOS filesystems' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Automatically delete Mac OS X dot files from MS-DOS filesystems
Authored by: lsloan on Feb 07, '11 07:48:52AM

There's a small mistake in the script when posting it. It won't hurt anything, but it doesn't do everything I intended it to do, either. I've emailed crarko about it and asked him to edit the hint.

---
Lance E Sloan



[ Reply to This | # ]
Automatically delete Mac OS X dot files from MS-DOS filesystems
Authored by: crarko on Feb 07, '11 08:13:52AM

Got it. Thanks!

Craig A.



[ Reply to This | # ]
Automatically delete Mac OS X dot files from MS-DOS filesystems
Authored by: DFW-Patrick on Feb 15, '11 12:31:52PM

I made a mistake in the steps, and it seems I incorrectly renamed umount-original. I can't find the file in sbin. It's gone, and when I do a Search, it's gone as well. Now, I an unable to unmount disks, and it says they are still in use. Is there a way to restore it?



[ Reply to This | # ]
Automatically delete Mac OS X dot files from MS-DOS filesystems
Authored by: lsloan on Feb 16, '11 07:33:42AM

Just so other readers know, you emailed me about this and you ended up doing an "Archive and Install" from the OS DVD.

Other possible solutions:

1. Use "sudo -s" and "history" commands in Terminal.app to find out where you copied the umount program to, then copy it back.

2. Copy umount from another computer with similar architecture and OS version.

---
Lance E Sloan



[ Reply to This | # ]
Automatically delete Mac OS X dot files from MS-DOS filesystems
Authored by: Anonymous on Feb 07, '11 08:46:11AM
You forgot the final step: "Never update your system" :-P
I prefer Do Something When.

[ Reply to This | # ]
Automatically delete Mac OS X dot files from MS-DOS filesystems
Authored by: lsloan on Feb 07, '11 11:39:41AM

Yes! You're absolutely right. :)

I'll probably do a bit more work on my script, maybe make an installer for it so that it's easy to reinstall after an update.

---
Lance E Sloan



[ Reply to This | # ]
Automatically delete Mac OS X dot files from MS-DOS filesystems
Authored by: lsloan on Feb 08, '11 08:34:31AM

In response to your comment, I looked up "Do Something When". It's a great concept and I'd rather use something like that than the wrapper I wrote for umount.

However, the site for DSW seems to be down more often than it's up, but I did manage to get connected after a while and download it. I installed it, then ran the preference pane. I was told that to use it, System Preferences would need to restart. I've seen that kind of thing before, so I wasn't surprised. The surprise came when I quit System Preferences, then some time later opened the DSW pane again. System Preferences again told me that it would need to restart. So as an experiment, I quit System Preferences and reopened the pane several times in a row. *Every time* System Preferences said it needed to restart.

Then I looked into the contents of the prefPane for DSW. I found that it contains multiple nested copies of itself. I think something is very wrong there. I think the developer needs to do some work on it.

Also, I wish that DSW could be told to run its rules on volumes of a certain type rather than specific names. I use a lot of external USB drives and I hate to make a rule for each one of them.

I hope the author will make some updates to DSW soon.

---
Lance E Sloan



[ Reply to This | # ]
Automatically delete Mac OS X dot files from MS-DOS filesystems
Authored by: displaced on Feb 08, '11 08:45:50AM

The System Preferences restarts are most likely nothing to worry about.

Presumably you're running a Mac that's 64-bit capable. But it appears DSW's System Preferences plugin is still 32-bit only. The 64-bit System Preferences process needs to quit and re-open in 32-bit mode in order to load the DSW plugin.

You can verify this by checking the title bar of the System Preferences window after it's restarted. It'll say something like <b>Do Something When (32-bit)</b>



[ Reply to This | # ]
Automatically delete Mac OS X dot files from MS-DOS filesystems
Authored by: lsloan on Feb 08, '11 11:13:55AM

Yes, you're right, it did say "32-bit" when it ran. The restarts are annoying, but that's not the main reason I don't like it.

---
Lance E Sloan



[ Reply to This | # ]
Automatically delete Mac OS X dot files from MS-DOS filesystems
Authored by: Anonymous on Feb 08, '11 09:13:20AM

Interesting. I installed it a while ago when it worked, so I didn't get that little surprise.

Okay, so don't use DSW until it's fixed.



[ Reply to This | # ]
Apple should have fixed this years ago.
Authored by: b00le on Feb 07, '11 09:04:33AM

There is a similar problem arising when creating zip archives and writing CD/DVDs. There are utilities to do it (Blue Harvest), but I can't imagine why this functionality is not built into the system.



[ Reply to This | # ]
Automatically delete Mac OS X dot files from MS-DOS filesystems
Authored by: joeyblades on Feb 07, '11 10:36:17AM

Three things:

  1. Apple recommends that you do a dot_clean before the find-and-rm operation.
  2. Sometimes you need to remove the dot files while the drive is still mounted. This is because when you're dumping visible files in the trash, the leftover dot files can take up a lot of room... preventing you from moving over new files.
  3. I'm (personally) a little nervous about the way you've automated this... for multiple reasons.

TIMTOWTDI - I chose a slightly different approach... I've been thinking about posting it, but it's a little more complicated. I have a bash script that is called by an AppleScript that is called by pushing a button on a Finder toolbar. I just push the button right before I unmount... One could choose to integrate the unmount into the button as well, but, as I mentioned, sometimes I want to clean the dot files and stay mounted.

Also, I have a failsafe mechanism that will prevent the dot file removal from executing on an unintended volume. So I can allow the removal of dot files from the multiple flash drives that I shuttle around between devices and I can NOT inadvertently remove the dot files from the large-ish (MS_DOS formatted) portable drive that contains my music that I shuttle between my Mac and my PC (for which I want the dot files preserved).

If there is sufficient interests, I can share the details of my alternative solution.



[ Reply to This | # ]
Automatically delete Mac OS X dot files from MS-DOS filesystems
Authored by: lsloan on Feb 07, '11 11:45:14AM

I'd love to see your solution.

I actually thought of doing something like that, with an AppleScript that I run before ejecting, but I wanted it to be a little more automatic. Mostly because I was going to give this to some people who are not as technical and I wanted it to be easy for them. I can see how that kind of solution would help in the situation you mentioned in #2, though.

I'll look up dot_clean to see what that is. I did a lot of Google searches and I didn't see mention of that until now.

---
Lance E Sloan



[ Reply to This | # ]
Automatically delete Mac OS X dot files from MS-DOS filesystems
Authored by: joeyblades on Feb 08, '11 12:23:35PM

I threw together a web page detailing my solution. You can find it here. Let me know what you think and if you have any suggestions.

Some of those droplets might be an even easier solution... but I like to have access to the guts... better the devil I know...



[ Reply to This | # ]
Automatically delete Mac OS X dot files from MS-DOS filesystems
Authored by: lsloan on Feb 08, '11 12:29:05PM

Great! I'll give it a look.

Meanwhile, I'm making changes to my script to make it better and safer. So far, I've added a Finder dialog box that pops up and asks the user whether they would like to clean the MS-DOS filesystem before ejecting it. (The default answer is "No".) I'm also changing the find command to be more efficient and to delete only known Mac OS X problem dotfiles, like .DS_Store, .Trash, etc.

---
Lance E Sloan



[ Reply to This | # ]
Automatically delete Mac OS X dot files from MS-DOS filesystems
Authored by: joeyblades on Feb 08, '11 04:39:54PM

Actually, the ones that give me the most trouble are the "._name" files that often show up with mp3s. I have two players that will try to read these files adding unpleasant delays and generating some random noise.

If you don't shuttle a lot of mp3s around you probably never noticed one.



[ Reply to This | # ]
Automatically delete Mac OS X dot files from MS-DOS filesystems
Authored by: lsloan on Feb 09, '11 06:40:47AM

Yes, I've seen the "._" files. They show up with MP3s, JPGs, and movies, depending on which software one uses. I often see "._.Trash" along with ".Trash", too. I forgot to mention that I've also added a call to dot_clean to my script to clean them up.

I wish it were easy for hint authors to update their hints here. Maybe when I consider my solution to be as "perfect" as it can be, I'll ask crarko to update this hint.

---
Lance E Sloan



[ Reply to This | # ]
Automatically delete Mac OS X dot files from MS-DOS filesystems
Authored by: afingal on Feb 07, '11 12:27:06PM

I wonder if it would make sense to use an AppleScript folder action or Automator workflow attached to the USB stick that would delete the dot files. That way you could have them deleted whenever the folder/volume is modified.



[ Reply to This | # ]
Automatically delete Mac OS X dot files from MS-DOS filesystems
Authored by: lsloan on Feb 08, '11 08:38:30AM

That was my very first thought. I tried, but I couldn't find a way to run an AppleScript just before the volume is ejected.

---
Lance E Sloan



[ Reply to This | # ]
Automatically delete Mac OS X dot files from MS-DOS filesystems
Authored by: jrobert on Feb 07, '11 02:38:08PM

Look up a small app called (appropriately) "Clean up SMB Mess". You drop your device onto it and it it cleans up the dot files and offers to dismount the device for you. It's simple, and makes no mods to your system.



[ Reply to This | # ]
Automatically delete Mac OS X dot files from MS-DOS filesystems
Authored by: TimBonnici on Feb 07, '11 02:49:00PM
Of course you could just install Blue Harvest which costs $16.95 and does a very nice job of sorting this and related problems out. (I'm not affiliated in any way with Blue Harvest, just a satisfied user.)

[ Reply to This | # ]
Automatically delete Mac OS X dot files from MS-DOS filesystems
Authored by: Rick67 on Feb 07, '11 10:50:35PM

If you don't feel adventurous in Terminal like me, there is also OptimUSB (freeware).



[ Reply to This | # ]
Automatically delete Mac OS X dot files from MS-DOS filesystems
Authored by: lsloan on Feb 08, '11 08:41:40AM
OptimUSB is not free. It now costs US $0.99 and is available only in the Mac App Store.
---
Lance E Sloan
Edited on Feb 08, '11 08:44:42AM by lsloan


[ Reply to This | # ]
Automatically delete Mac OS X dot files from MS-DOS filesystems
Authored by: hanxkannx on Feb 08, '11 12:25:33AM

I use Hidden Cleaner for unmount all of my (DOS) USB-Pens and hard drives. Only drag the mounted device on the "hidden cleaner" icon (in the dock) and it will delete all mac-files and unmount the device. If you do not want to delete these files, you can drag the icon in the default trash in the dock.
You can find hidden cleaner here: http://www.macupdate.com/app/mac/27416/hidden-cleaner



[ Reply to This | # ]
Automatically delete Mac OS X dot files from MS-DOS filesystems
Authored by: bowlingb on Feb 08, '11 09:38:03AM

There is an OSX appliction called nude that also handles cleaning up .ds_store files. The help file describes it as
"Nude (Non–Unix DS_Store Eliminator)
Nude 1.2 (1) is an Objective-C (non-unix) utility to remove .DS_Store files"
You can select folders from a dialog or simply drop the folder on the application. I have used it for a couple of months and haven't had any problems.



[ Reply to This | # ]
Dangerous to rewrite umount
Authored by: googoo on Feb 09, '11 11:50:02AM

It is generally not a good idea to replace system executables like umount. A better idea would be to give your script a different name like umdos or something and move it to a directory in your path. You would call it by its name to use it. This way there are no unintended consequences when something else uses umount.

-Mark



[ Reply to This | # ]
Dangerous to rewrite umount
Authored by: lsloan on Feb 10, '11 09:36:40AM

I agree, it's dangerous! :)

That danger is why I put the cautioning message in my hint. This hint is not for the faint of heart.

I purposely wanted to replace umount with this script because I wanted it to execute automatically whenever the user ejects a disk. So this works whenever the user chooses any of the Mac OS X eject methods (eject icon, menu items, etc.).

I think that if one wanted a good solution that doesn't replace umount, look at the one suggested by user "joeyblades" here:

http://hints.macworld.com/comment.php?mode=view&cid=122757

Otherwise, one of the droplet or helper applications mentioned in these comments might be a good choice.

---
Lance E Sloan



[ Reply to This | # ]
Automatically delete Mac OS X dot files from MS-DOS filesystems
Authored by: fireflux on Feb 15, '11 08:54:51AM

I asked a friend of mine to print a pdf file for me on his mac and gave him my usb stick. He printed the file and returned the stick immediately. Later on I noticed that my home folder that I keep on that stick misses lots of important files like .bashrc .vimrc and so on. He appeared to be an "advanced" mac user as you are.



[ Reply to This | # ]
Automatically delete Mac OS X dot files from MS-DOS filesystems
Authored by: lsloan on Feb 15, '11 12:40:10PM

Yes, I'm aware that could happen. That's why I wrote in the hint:

This may be obvious, but if you intentionally copy dot files (like your .bashrc file) to your MS-DOS filesystem, they will be deleted when you eject the filesystem. A couple possible ways to prevent this would be to put your dot files into a ZIP file or change this script to be more specific about which files it deletes.

If your friend had used this hint and that led to the loss of your files, then you have my sincere apologies. I've never heard of somebody keeping their home directory on a flash drive, but anything's possible.

If it's any consolation, I've changed the copy of the script I used to be safer. It only deletes certain specific dot files that Mac OS X creates, not just any dot file as the one in this hint does. When I get some time, I'll clean that script up and ask crarko to put the new script in place of the old one.

---
Lance E Sloan


[ Reply to This | # ]
Automatically delete Mac OS X dot files from MS-DOS filesystems
Authored by: Geekier on Feb 15, '11 11:17:22AM

I'm in need of help. I tried following these steps in Terminal and regrettably one of them didnt work as intended. The issue I'm having now when I stick in a flash drive or any mountable device, I can't eject it from my mac. Any easy terminal fix to reverse this?



[ Reply to This | # ]
Automatically delete Mac OS X dot files from MS-DOS filesystems
Authored by: axforts on Feb 16, '11 05:25:10PM

I've got the same problem.

Heres what I've done

ran terminal, became root.

used the cd /sbin command

opened textedit and made the file, renamed to umount (no extention)

ran the chmod command.

no longer can eject disks.



[ Reply to This | # ]
Automatically delete Mac OS X dot files from MS-DOS filesystems
Authored by: axforts on Feb 16, '11 05:37:14PM

I figured it out. Heres how to do it.

What seems to have happened is when I did this, I never moved the new umount into the /sbin directory.

What we've done is simply renamed the old umount to umount-orig and left the OS without a umount file.

So you've got two options

1- put the umount file you've made in /sbin (open terminal and type "open /sbin" without quotes. and drag it in

2-the safer option that i did

open terminal

type without quotes

"sudo -s"

"password"

"cd /sbin; mv umount-orig umount"

that will rename the file back to umount. problem solved.



[ Reply to This | # ]
Automatically delete Mac OS X dot files from MS-DOS filesystems
Authored by: Geekier on Feb 17, '11 04:10:40PM

Thanks for that, I followed your "safer approach" and I can now eject any external device just like before.

My only remaining issue is my external HDD just has Read permission and I can't figure out how to change it back to Read & Write. I tried in the 'Info' window of my HDD to click on the lock and manually add Write permissions but it stays gray and I'm unable to manually edit the permissions. Pictured here: http://i.imgur.com/KrnEO.png

Does anyone know how to change my external HDD permissions back to Write & Read in Terminal or any other method?



[ Reply to This | # ]
Automatically delete Mac OS X dot files from MS-DOS filesystems
Authored by: axforts on Feb 20, '11 05:20:52PM

http://www.askdavetaylor.com/why_is_my_mac_hard_drive_suddenly_readonly.html

You can try that and let me know how it works



[ Reply to This | # ]