I have following in a directory:
dir1
dir2
file1
file2
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 ?
It's because of the
.
in the output..
also getstar
ed.Use this intead, it will exclude both;
.
anddir1
:See the contents of
documents.tgz
:tar also has an "exclude" option you can add one or more times.
For example:
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.