Take the 2-minute tour ×
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
add comment

2 Answers

up vote 3 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
add comment

This gives you what you want:

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

Your Answer

 
discard

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.