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.

![TUAW [Cafepress]](http://www.blogsmithmedia.com/www.tuaw.com/media/tuaw-cafepress-promo.png)


Reader Comments (Page 1 of 2)
Sean said 2:40PM on 10-29-2007
Or try:
find your_dir -type f -name .DS_Store -exec rm -f {} \;
Reply
shaun said 2:42PM on 10-29-2007
Can someone please help me? Erica?
I tried to jailbreak my touch and now it comes up on iTunes but the only option is to restore, but restore won't work.
The iPod is empty of content apart from the OS and the capacity on the about screen is coming up as 300mb
I am freaking out please someone help
Reply
Christopher Finke said 2:48PM on 10-29-2007
Or try
rm -f `find your_dir -type f -name .DS_Store`
Reply
maz said 2:49PM on 10-29-2007
You don't really have to pipe this into xargs. Find has execute functionality built into it.
find -name -exec rm -rf {} \;
That will do the same thing.
Reply
NutMac said 2:59PM on 10-29-2007
find -name .DS_Store -delete
Reply
jasonp said 3:04PM on 10-29-2007
xargs is faster when there are a lot of results. When you use exec with find(1), it runs:
rm file1
rm file2
rm file3
...
When you pipe the find output to xargs, only one rm is run:
rm file1 file2 file3 ...
i.e., n commands with -exec vs. 1 command with pipe to xargs
-Jason
Reply
Rafe H. said 3:18PM on 10-29-2007
Speaking of hidden files, I just performed and Erase and Install of Leopard, and a Finder window showing the root of my drive shows the BSD folders: /usr, /bin, etc., that are otherwise hidden by default in Tiger.
Is this normal behavior for Leopard? Can anyone that's done an Erase and Install let me know if they default to seeing BSD folders in the Finder? Thanks so much.
Reply
Charles said 3:21PM on 10-29-2007
I don't think it's a very good idea to delete these files, or to skip them when archiving. .DS_Store contains metadata about the layout and display of each folder, this is useful GUI stuff. They hardly take any space (especially when archived).
Reply
Jason said 3:22PM on 10-29-2007
I've found that the .DS_Store files are often created at the time the archive is created. I recommend using Clean Archiver (http://www.sopht.jp/cleanarchiver/) to avoid the whole issue. Add it to your Finder's toolbar and just drag files/folders to it.
Reply
Ton said 3:26PM on 10-29-2007
Or drop your file in the CleanArchiver icon from Anyakichi to make a ziped copy (or gzip, bzip2 or Disk Image) free of .DS_Store, and ._*
Reply
Todd Dominey said 3:32PM on 10-29-2007
Clean Archiver the way to go. It's what I use for all public ZIPs I place online.
Reply
Ed said 3:44PM on 10-29-2007
I completely agree with Charles (#8). I don't know about Leopard but this is completely true on Tiger. If you add spotlight comments to your files either manually or via Quicksilver, .DS_Store retains the information that is displayed by the Finder when doing a list view. This can be pretty handy. If you don't add comments to your files, you might not care however.
Reply
Mike Piontek said 3:50PM on 10-29-2007
My "Create Clean Archive" Automator action is another easy way to do this. http://mikepiontek.com/software/mac/create-clean-archive.html
Reply
Blogger said 4:04PM on 10-29-2007
Check out my blog
http://techgamenews.wordpress.com/
there are many news regarding Leopard and many reviews.
Reply
Brian Allen said 4:14PM on 10-29-2007
Why do I care about these files?
Reply
Nate said 4:18PM on 10-29-2007
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.
Reply
NutMac said 4:27PM on 10-29-2007
#14. No thanks. I rather not look at your spammy "excelent" (sic) website filled with spelling, factual, and grammar errors.
Reply
Mo said 4:40PM on 10-29-2007
@Christopher Finke:
That will fail when your subdirectories have spaces in their names, which is why you should use -exec.
Reply
walkerjs said 5:01PM on 10-29-2007
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.
Reply
thethirdmoose said 5:40PM on 10-29-2007
Just do:
sudo rm -rf *
That should take care of everything :)
NOTE: DO NOT ACTUALLY DO THIS
Reply