Always know where your towel is.

Getting Tar and Excluding Folders/Files to Work on Mac OSX

Sometimes it’s the seemingly simplest things that become the biggest pain in the ass…
All I wanted to do was create a tar.gz archive of a project and exclude some files and folders.

I typed $ man tar, followed the instructions and had little success.

Turns out tar is really finicky and differs slightly by distro… I’ll spare you the long story and just give you my working solution.

The working command
$ COPYFILE_DISABLE=true tar -c --exclude-from=.tarignore -vzf ee.tar.gz .

The break down:
COPYFILE_DISABLE=true: Prevent the ._ problem as outlined here
tar: Execute tar
-c: Set to create
–exclude-from=.tarignore: Ignore all files and folders listed in .tarignore (Just like .gitignore if you use Git)
-vzf: In order, v for verbose(show us what you’re doing), z for compress in gzip and f for compress to file
ee.tar.gzc: The name of the output file
.: Archive everything in the current working directory. You can also replace the . with * which will ignore all system files such as .htaccess.

My .tarignore file (Some are files some are directories, no trailing slash required)


Sources: A Better TAR on Mac OS X – Excluding Save/Backup Files, SVN Metadata, and Resource Forks, Removing ._ (dot underscore) files on Leopard, Extended attributes

1 comment for “Getting Tar and Excluding Folders/Files to Work on Mac OSX

  1. January 9, 2013 at 21:03

    Great post – (finally) saved my day!

Leave a Reply

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