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.

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

share|improve this question

migrated from stackoverflow.com May 20 '11 at 3:10

This question came from our site for professional and enthusiast programmers.

3 Answers 3

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
share|improve this answer
    
Thanks it works –  user493619 May 19 '11 at 12:23
 --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
share|improve this answer
    
thanks, it helpful to understand the command more clearly –  user493619 May 19 '11 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.

share|improve this answer
    
i am not clear about how to use this command –  user493619 May 19 '11 at 12:14
    
thanks for the solution –  user493619 May 19 '11 at 12:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.