Next

Remove Invisible Files From Folder · 1262 days ago

This is a Mac OS X shell script used to remove invisible files from windows shares or media devices like mp3 players or USB memory drives. The script will only remove the annoying .DS_Store and ._filename.ext files from the selected folder.

The ._filename.ext files that littered my mp3 player were really annoying because they show up in the playlist. So for every file.mp3 there was an empty ._file.mp3.

Here is the script:

#!/bin/sh
if [ -z $1 ]
 then
  dir="."
  echo Cleaning current directory ...
 else
  dir=$1
  if [ -d $1  ]
   then
    echo Cleaning $1 directory ...
   else
    echo Not a valid directory.
    exit 1
  fi
fi
find $dir -name .DS_Store -exec rm -i "{}" \;
find $dir -name "._*" -exec rm -i "{}" \;
exit 0

You can remove the -i after rm if you don’t want to confirm every file.

If you don’t know how to make this into an executable, then you probably shouldn’t. And, ONLY run this on windows shares and USB devices; the mac uses these files you should probably leave them on your mac.

But here’s how:

  • open the Terminal
  • open pico – yourname% pico
  • copy and paste the code
  • type ctrl-o [save]
  • enter a name for your script (I used rmds: for remove .DS)
  • type ctrl-x [exit pico]
  • make it executable by all – yourname% chmod a+x rmds
  • mv to a folder that is in the $path (so the shell can find it)
  • try – yourname% sudo mv rmds /usr/local/bin/rmds
  • if there is no /usr/local/bin then
  • try – yourname% sudo mv rmds /usr/bin/rmds
  • enter your admin password
  • yourname% rehash [otherwise the new script may not be found]
  • Do not test in your home folder!! It will try to delete the files .DS and ._files from your entire home folder.

Usage:

  • either cd to the folder and type rmds
  • or type rmds then add the path to the folder like yourname% rmds /volumes/usbDrive/

Comment

  1. I am running OSX Tiger 10.4.4 and wanted to use your terminal script for removing the invisible files on my Sony Ericsson W600i walkman phone. The software for the phone is only for PC’s so I simply mounted the phone as a USB device and copied across. The only problem was, of course, I also got all the invisible file, which can not be deleted on the phone or from within OSX- even when I show invisible files.

    I am trying to follow your directions, but when I try to open pico, the terminal says command not found. See result:

    
    howard-katzs-Computer:~ howardkatz$ howardkatz% pico
    -bash: howardkatz%: command not found
    
    

    Any ideas or have you updated the script to run on Tiger or do you know of any other utility to let me copy across my data (photos, music, contacts) that is mac based?

    Regards,
    Howard Katz
    howard katz    1046 days ago    #
  2. This is a pretty generic script and should work on any version of OS X and probably on linux too, although I haven’t tested it.

    You don’t need to use pico; you could use emacs, vi or even TextEdit. If you use TextEdit make sure you go to Format->Make Plain Text and then save without the extension and uncheck the If no extension is provided, use .txt.

    Then follow the rest of the instructions above.

    Or if you want Pico:

    Dowload from ftp://ftp.cac.washington.edu/pine/bin/pico-bin.osx-10.4.Z

    In the terminal cd to the folder where you downloaded it to; then you need to unzip, make it executable and move to somwhere in the $path. Try:
    
    gunzip pico-bin.osx-10.4.Z
    sudo chmod a+x pico-bin.osx-10.4.Z
    sudo mv pico-bin.osx-10.4.Z /usr/local/bin/pico
    
    

    Andrew    1046 days ago    #
  3. Thanks so much for your script! I just transfered a photo directory from a Mac computer to a Linux computer, and the Linux photo manager (f-spot) would choke every time it came a cross one of the mac’s dot files. I just piped ‘yes’ into the script and all my problems went away. Thanks again for sharing this.
    Chris    727 days ago    #