Untar only folder structure from a tar ball

I have a tar file hello.tar which is 95 GB.

hello.tar has many files and folders including some tar files as well.

I wish to create a new tar ball which should maintain only the folder structure of hello.tar and the tar ball within the hello.tar

So basically the idea is to untar hello.tar in a way that only the folder structure is extracted.

Then the folder structure is used to create a new tar which will be only a few kbs along with maintaining the directory structure of hello.tar.

 uname -a
SunOS mymac 5.11 11.2 sun4v sparc sun4v

Kindly help.

With a Solaris 10 or earlier system, assuming that your tar file is named tarfile , the following two step sequence should extract only the directories from your tarfile (by extracting everything from the archive except files that are not directories):

tar tf tarfile | grep -v '/$' > exclusions.$$
tar xfX tarfile exclusions.$$
rm -f exclusions.$$

With Solaris 11, you might need:

tar tf tarfile | grep -v '/$' > exclusions.$$
tar xf tarfile -X exclusions.$$
rm -f exclusions.$$
2 Likes

I will test it and update this thread in sometime.