I have following in a directory:


I want to tar up everything except dir1

When I do:

find . -path '*dir1*' -prune -o -print

I don't see dir1 in the output ( as expected)

But when I do:

find . -path '*dir1*' -prune -o -exec tar -czvf documents.tgz  '{}' \+

I see that dir1 also gets tarred up in documents.tgz. Why ?

  • You could just use * instead of . to exclude the current working directory. Oct 15, 2014 at 8:38

2 Answers 2


It's because of the . in the output. . also gets tared.

Use this intead, it will exclude both; . and dir1:

find . -not -path '*dir1*' -not -path "." -exec tar -czvf documents.tgz  '{}' \+

See the contents of documents.tgz:

$ tar tf documents.tgz

tar also has an "exclude" option you can add one or more times.

For example:

tar czvf documents.tgz --exlude dir1 --exclude dir2 * 

Note: I would rather create the tar in a different directory, to avoid including documents.tgz itself in tar in case you run the command another time without deleting it in the meantime.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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