I want to create tar file of a folder but this folder contains some tar.gz files like abc.tar.gz, pqr.tar.gz which i don't want to include so how to exclude this files while making the tar
3 Answers
--exclude=PATTERN
When performing operations, `tar' will skip files that match
PATTERN.
--exclude="*.tar.gz"
--exclude-from=FILE
-X FILE
Similar to --exclude, except `tar' will use the list of patterns
in the file FILE.
--exclude-from="File.txt"
File.txt
abc.tar.gz
prq.tar.gz
-
thanks, it helpful to understand the command more clearly– user493619May 19, 2011 at 12:23
What about something like:
find ./ -name '*.tar.gz' > /tmp/excludefiles
tar -czvf newarchive.tar.gz -X /tmp/excludefiles foldertotar/
I haven't test it. It's only idea how to solve it.
EDITED:
It's even simpler:
tar -czvf newarchivename.tar.gz --exclude '*.tar.gz' foldertobetarred/
This solution is tested and works.
-
i am not clear about how to use this command– user493619May 19, 2011 at 12:14
You can use the --exclude functionality in tar
@tmp$ ls test
abc.tar.gz adfd asdfd dfcvdf dfdf efdfefef pqr.tar.gz test
@tmp$ tar -cvzf test.tar.gz test --exclude="*.tar.gz"
test/
test/adfd
test/dfcvdf
test/test/
test/test/abcd
test/efdfefef
test/dfdf
test/asdfd