2

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 3

5
 --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
1
  • thanks, it helpful to understand the command more clearly
    – user493619
    May 19, 2011 at 12:23
1

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.

1
  • i am not clear about how to use this command
    – user493619
    May 19, 2011 at 12:14
0

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
0

You must log in to answer this question.