Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

This is driving me crazy. I want to tar a directory, but exclude some files. This is my command:

tar -zcvf $NAME-$VERSION.tar.gz $NAME-$VERSION --exclude='.git' --exclude='.gitignore'

While the above command works on RedHat EL5, it doesn't work on Mac OS 10.8.2. I have tried replacing the ' with ", \' and \". I have tried removing the equal signs. Nothing works.

What am I doing wrong?

share|improve this question

2 Answers 2

up vote 8 down vote accepted

All the options need to be together before the arguments, and the -f flag needs to precede the tar file:

tar -zcv --exclude='.git' --exclude='.gitignore' -f $NAME-$VERSION.tar.gz $NAME-$VERSION
share|improve this answer
If you do tar --help, does the --exclude option appear in the help? I don't know OSX but perhaps there's a gtar instead of the stock tar. – Flup Mar 1 '13 at 14:23
Ah I see it :) try this: tar --exclude='.git' --exclude='.gitignore' -zcvf $NAME-$VERSION.tar.gz $NAME-$VERSION The -f flag expects a filename as the next argument. – Flup Mar 1 '13 at 14:24
Sorry yes, edited. I'm new here so bear with me! – Flup Mar 1 '13 at 14:27
Can attest that this works on a Mac - 10.9. Took me a while to find the right version of this which is why I leave my comment here! – JohnAllen Oct 23 at 1:38

This gives you what you want:

tar czvf $NAME-$VERSION.tar.gz $NAME-$VERSION --wildcards --exclude=.git --exclude=.gitignore
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.