views:

197

answers:

2

Hi,

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.

A: 

Yup.

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

Should do the trick.

David Wolever
And, of course, wrap that up in a small script (or copy+paste the line 23 times ^_^) and you should be golden.
David Wolever
thanks but that didn't actually work.
StarCub
If you could explain why it didn't work, there's a better chance I'd be able to tell you what's wrong… But since you've already solved it, I guess that isn't too important.
David Wolever
@StarCub: I'm guessing you need another `z` in there somewhere and maybe one less `O`. Perhaps `tar -xzOf foo.tar.gz bar1.tar.gz | tar -xz foobar1.tar`
Dennis Williamson
A: 

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 `ls *.tar.gz`
    do
        echo "Untaring - $next"
        tar -xzf $next -C ~/foo
    done
exit 0

hope this will help someone.

StarCub
Although your solution worked, if you want to learn why you shouldn't use the output of ls in the way you have, http://stackoverflow.com/questions/1956144/bash-script-to-rename-all-files-in-a-directory/1956165#1956165 ... I find the answers (to that question) which use the `find` command interesting in particular.
James Morris