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)

.DS_Store
.git
.gitignore
.sass-cache
db_dumps
logs
scss
source

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

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

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>