Write a subset of a huge tar file to a new tar file without unpacking

I have a huge tar tar t20 archive huge.tar.gz

from which I want to extract a subset and put it in a new tar tar file archive subset.tar.gz

without first extracting the whole huge file. For example, if the content listing is huge.tar.gz

:

    tar tfz huge.tar.gz
    dir1/bla/bla.bla
    dir2/bla/bla.bla
    dir3/bla/bla.bla

      

how can i create a new tar file subset.tar.gz

containing only dir1:

    tar tfz subset.tar.gz
    dir1/bla/bla.bla

      

+3


source to share


2 answers


This is a two step process. First you need to extract the directory from the tarball:

tar -zxf huge.tar.gz dir1

      



And then you need to compress it:

tar -zcf subset.tar.gz dir1

      

+2


source


The only thing I found from donig is to delete anything you don't want from the archive (when using the tar version that supports -delete), you can do the following.



gzip -d < huge.tar.gz |tar --delete bla2 bla3 |gzip >part_huge.tar.gz

      

0


source







All Articles