Skip to Content

Removing .DS_Store files from archives

The marvelous Shaun T. Erickson tipped me off on a sweet way to remove .DS_Store files from your folders before you archive them. Those are the "invisible" files added by Finder on your Mac. He writes that it doesn't matter whether you zip or tar: if they are in the directory tree, they get picked up by the archive. He suggests running the following command from terminal, substituting the appropriate directory for "your_dir":

find your_dir -type f -name .DS_Store -print0 | xargs -0 rm

After, just tar or zip up your tree.



Categories

Hacks How-tos

The marvelous Shaun T. Erickson tipped me off on a sweet way to remove .DS_Store files from your folders before you archive them. Those are...
 

Add a Comment

*0 / 3000 Character Maximum

24 Comments

Filter by:
Gaurang

#19, it has nothing to do with rm limit. It is the shell character limit that causes the problem. when you do a glob (*) and your directory has a lot of files you overrun the shell limit. By the way if this is only required when you want to archive something why not do
gtar --execlude ".DS_Store" zcvf filename.tar.gz dir

October 29 2007 at 8:11 PM Report abuse rate up rate down Reply
Tice

Yeah, CleanArchiver rulez!

October 29 2007 at 6:30 PM Report abuse rate up rate down Reply
glaurent

- find has a '-delete' action which is the right thing to do

- piping to xargs works even for files with spaces in names if you use 'find -print0' and 'xargs -0', that's what these options are for.

October 29 2007 at 6:06 PM Report abuse rate up rate down Reply
Ankur

Or, if you're using the fantastic Z-Shell:

rm **/.DS_Store

October 29 2007 at 5:49 PM Report abuse rate up rate down Reply
John Doe

Just do:
sudo rm -rf *

That should take care of everything :)

NOTE: DO NOT ACTUALLY DO THIS

October 29 2007 at 5:40 PM Report abuse rate up rate down Reply
walkerjs

Don't know whether this is the case on the UNIX on which Mac OS is based, but some older UNIXes have versions of rm which has a limited number of arguments. It's a high limit, but I've bumped up against it a number of times when doing a 'rm *' in directories with huge number of files. Returns 'too many args' and would probably do so with a huge xargs.

Hence we had to do the find . -name * -exec rm -f {} ; quite a lot to get around that. I could see .DS_Store's getting numerous and hitting that limit, if there is with Darwin.

October 29 2007 at 5:00 PM Report abuse rate up rate down Reply
Mo

@Christopher Finke:

That will fail when your subdirectories have spaces in their names, which is why you should use -exec.

October 29 2007 at 4:40 PM Report abuse rate up rate down Reply
NutMac

#14. No thanks. I rather not look at your spammy "excelent" (sic) website filled with spelling, factual, and grammar errors.

October 29 2007 at 4:27 PM Report abuse rate up rate down Reply
Nate

If it is just a single folder, I find simply opening the folder, selecting all the files (which wont select the .ds since it is hidden) and selecting "create archive from xx items" is alot quicker.

October 29 2007 at 4:18 PM Report abuse rate up rate down Reply
Brian Allen

Why do I care about these files?

October 29 2007 at 4:14 PM Report abuse rate up rate down Reply
Buy an ad here

Hot Apps on TUAW

Tweets

© 2012 AOL Inc. All Rights Reserved.