How to clean up those Mac OSX hidden files

I’ve written a simple batch file to remove those hidden files that Mac OSX leaves all over shared drives to annoy us Windows users.

del /s /a:h ._*
:: http://en.wikipedia.org/wiki/Resource_fork

del /s /a:h .DS_Store
:: http://en.wikipedia.org/wiki/.DS_Store

del /s /a:h .Trashes
:: http://en.wikipedia.org/wiki/Recycle_bin_(computing)

@pause

How to use

Copy the code into a text file, rename it cleanOSX.bat and run it from the root of the drive you wish to clean. The script will look through all subfolders, deleting any hidden file or folder with a name that begins with ._, or that matches .DS_Store or .Trashes. Depending on the number of these files on your drive, the process of deleting them could take some time.

Where do these files come from?

The resource fork

The resource fork is a construct of the Mac OS operating system used to store structured data in a file, alongside unstructured data stored within the data fork. A resource fork stores information in a specific form, such as icons, the shapes of windows, definitions of menus and their contents, and application code (machine code). For example, a word processing file might store its text in the data fork, while storing any embedded images in the same file’s resource fork. The resource fork is used mostly by executables, but every file is able to have a resource fork.

Currently, Mac OS X does support resource forks on Windows SMB shares by creating a hidden file in the same directory with the data fork file, with the characters β€œ._” at the beginning of the file name. However, this may be annoying for some users, especially because some Windows power users always keep hidden files visible. Besides, Windows does not treat those files correctly as the file itself is moved or removed.

http://en.wikipedia.org/wiki/Resource_fork

The Desktop Services Store

.DS_Store (Desktop Services Store) is a hidden file created by Apple Inc.’s Mac OS X operating system to store custom attributes of a folder such as the position of icons or the choice of a background image.

http://en.wikipedia.org/wiki/.DS_Store

The Trash folder

Under Mac OS X, when a file is deleted in Finder, it is moved to a .Trashes folder, and when viewing the device’s available space the space occupied by the deleted files is shown as occupied.

http://en.wikipedia.org/wiki/Recycle_bin_(computing)

15 thoughts on “How to clean up those Mac OSX hidden files

  1. ja

    hi! i couldnt find a way to run the file, not even as logged as root.
    do you have any ideas how can i run the file? thx

  2. guest

    Dear Ja

    you said logged in as root but this is a dos batch file and the term root etc is a unix/OSX term

    so you need to do this in windows

    programs run cmd
    then log onto the drive letter appropriately and cd

    then run the batch file you created or run the commands separately and manually

  3. calaverasgrande

    Great little scriptlet! Just saved me from having to cough up a script of my own to clean up our shared drive that is used by 5% macs, 95% PCs. Now to figure out how to turn that ._stuff ._off!

  4. bobwilson

    It doesn’t erase the hidden folders.

    You also got some of the code wrong. DEL command can’t erase folders, so this doesn’t work: “del /s /a:h .Trashes”. .Trashes is a folder.

    Here’s an updated script that will work in all situations, regardless of whether your mac litter is hidden or not. It also doesn’t bug you for confirmation. Hope it helps:

    del /s /a:h /a:a /q ._*
    del /s /a:h /a:a /q .DS_Store
    rmdir /s /q .Trashes
    rmdir /s /q .Spotlight-V100
    rmdir /s /q .fseventsd
    del /s /a:h /a:a /q autorun.inf
    del /s /a:h /a:a /q icon.ico
    @pause

  5. memroy

    Thank you ardamis and bobwilson.
    Worked a treat.
    I flick between both mac and win and the junk, especially trashes, clogs my memory stick.
    err am I right in assuming that win does not use ._ for *anything* ?
    I know it is safe on my memory stick but are there any w7 (or w8) things that use/need ._ ?

  6. derrick

    the best solution is to format your external drive in exFat. Solves the issue. And that’s from apple care.

  7. Nick Syrax

    I’m trying the del /s /a:h /a:a /q .DS_Store in the top level of the directory I am trying to clean and it’s telling me it “Could not find …”. I have tried running the command prompt as admin and it still doesn’t work. Any ideas?

  8. Ander

    Hi, thanks for the very very helpful hint !!!

    Trying to use it to get rid of some files….

    Any idea why:
    if exist “%letter%:\*.*” del /s /a:h /a:a /q %letter%:\*.eit

    is correct deleting all *.eit files

    but:
    if exist “%letter%:\*.*” del /s /a:h /a:a /q %letter%:\*.ts.cuts
    doesn’t work ??

    Thank you for help πŸ™‚

Leave a Reply

Your email address will not be published. Required fields are marked *