Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract nested tar.gz files easily?

I need to extract tar.gz a file. It's about 950mb. It has another 23 tar.gz files in it. Each of those 23 tar.gz files has one tar file in them. My questions is how I can easily extract all of them? Is there a commandline tool that I can use?

The structure is like the following:

foo.tar.gz
 ├───bar1.tar.gz
 │   ├───foobar1.tar
 ├───bar2.tar.gz
 │   ├───foobar2.tar
 ├───bar3.tar.gz
 │   ├───foobar3.tar
 ├───bar4.tar.gz
 │   ├───foobar4.tar
 ├───bar5.tar.gz
 │   ├───foobar5.tar
 ├───bar6.tar.gz
 │   ├───foobar6.tar
 |   ..........
 |   ..........
 |   ..........
 |   23 of them

Thanks in advance.

like image 350
StarCub Avatar asked May 06 '10 03:05

StarCub


3 Answers

You can use the --to-command argument to pass each extracted file to another program (on stdin). In this case, you pass it to another tar instance reading data from stdin.

tar --to-command='tar -xzvf -' -xzvf foo.tar.gz
like image 80
phobozad Avatar answered Nov 17 '22 13:11

phobozad


I ended up manually extracted foo.tar.gz and using the following shell script to extract those bar*.tar.gz files.

#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
for next in *.tar.gz
    do
        echo "Untaring - $next"
        tar -xzf $next -C ~/foo
    done
exit 0

hope this will help someone.

like image 4
StarCub Avatar answered Nov 17 '22 13:11

StarCub


Yup.

tar -xzOf foo.tar.gz bar1.tar.gz | tar -xO foobar1.tar

Should do the trick.

like image 1
David Wolever Avatar answered Nov 17 '22 14:11

David Wolever