You are not logged in.

#1 2004-03-30 21:11:35

punkrockguy318
Member
From: New Jersey
Registered: 2004-02-15
Posts: 711
Website

Recursively Extracting tar.gz archieves

How can I extract a bunch of archieves?

gzip -dc *.tar.gz | tar x

That only extracts one.  How can I do this recursively?


If I have the gift of prophecy and can fathom all mysteries and all knowledge, and if I have a faith that can move mountains, but have not love, I am nothing.   1 Corinthians 13:2

Offline

#2 2004-03-31 00:21:51

Xentac
Forum Fellow
From: Victoria, BC
Registered: 2003-01-17
Posts: 1,797
Website

Re: Recursively Extracting tar.gz archieves

I don't think recursively is the word you want.  That means you want to uncompress one and inside it there's another tar that you want to uncompress and inside that there's another one...

Luckily, that's the more difficult problem.

Try something like this:

for i in *.gz; do tar -xzf $i; done


I have discovered that all of mans unhappiness derives from only one source, not being able to sit quietly in a room
- Blaise Pascal

Offline

#3 2004-04-15 02:48:32

mr_ed
Member
From: Ottawa, ON, Canada
Registered: 2004-04-13
Posts: 72

Re: Recursively Extracting tar.gz archieves

Ah!  That makes sense!

I was trying to compile Gnome 2.6 from source (when I was running Slack on my main box), and I tried to find that out.
The answer I got back used the find command with -exec.  That worked well.  Unfortunately I was stuck on how to not individually cd to each folder, do ./configure && make && make install, cd .., and then move to the next folder.

Would this work?  (assuming that current folder only contains extracted folders)

for i in *; do cd $i; do ./configure; do make; do make install; do cd ..; done

(Do I need all those "do"s in there?)
This wouldn't jump into all subfolders, would it?

This is just a curiosity thing now, btw.  big_smile

Offline

#4 2004-04-15 04:48:18

razor
Member
From: Kiev, Ukraine
Registered: 2004-04-08
Posts: 16

Re: Recursively Extracting tar.gz archieves

You don't need so many do's smile

I think here the right script:

for i in *; do
  cd $i;
  ./configure;
  make;
  make install;
  cd ..;
done


Best wishes, Alexander Solovyov

Offline

#5 2004-04-15 12:27:59

i3839
Member
Registered: 2004-02-04
Posts: 1,185

Re: Recursively Extracting tar.gz archieves

I think this is better:

for i in *; do
    if cd $i &> /dev/null; then
        ./configure && make && make install;
        cd ..
    fi
done

Offline

#6 2004-04-15 19:00:21

mr_ed
Member
From: Ottawa, ON, Canada
Registered: 2004-04-13
Posts: 72

Re: Recursively Extracting tar.gz archieves

Thank you very much.  8)

I know this will work (though I haven't tried it on that group of files -- just some experimentation with it)

For the line "if cd $i &> /dev/null," I don't exactly understand how it works.

I understand that all output will be piped to /dev/null, but what is the & for?  Is it not going to "spawn" a separate instance of each cd?  Could you not just do "if cd $i > /dev/null?"

Offline

#7 2004-04-15 20:26:39

Xentac
Forum Fellow
From: Victoria, BC
Registered: 2003-01-17
Posts: 1,797
Website

Re: Recursively Extracting tar.gz archieves

instead of that if line, I think it's more understandable with something like this:

if [ -d $i ]; then


I have discovered that all of mans unhappiness derives from only one source, not being able to sit quietly in a room
- Blaise Pascal

Offline

#8 2004-04-16 02:02:48

mr_ed
Member
From: Ottawa, ON, Canada
Registered: 2004-04-13
Posts: 72

Re: Recursively Extracting tar.gz archieves

Heh.  That makes more sense.   lol

Offline

#9 2004-04-16 02:11:45

punkrockguy318
Member
From: New Jersey
Registered: 2004-02-15
Posts: 711
Website

Re: Recursively Extracting tar.gz archieves

What's a good guide for bash scripting?  I know the basics, but I want to know a little more.  I'm coming from a C backgruond, what would you reccomend reading?


If I have the gift of prophecy and can fathom all mysteries and all knowledge, and if I have a faith that can move mountains, but have not love, I am nothing.   1 Corinthians 13:2

Offline

#10 2004-04-16 15:17:24

i3839
Member
Registered: 2004-02-04
Posts: 1,185

Re: Recursively Extracting tar.gz archieves

http://www.tldp.org/LDP/abs/html/

"if [ -d $i ];" works, but my way is shorter wink. The &> /dev/null redirects both stdout and stderr, cd prints an error message when it fails, so to get rid of it I used &>, could as well use 2>. I think it's natural to try to cd into a dir, and if that succeeds then do the make stuff. With [ -d $i ] you get problems when you don't have permission to go into the dir (perhaps the correct way is to use pushd and popd and/or make's recursive feature, but don't know about configure then).

A variant:

for i in *; do
   if  [ -d $i ]; then
      cd $i && ./configure && make && make install && cd ..
   fi
done

Offline

Board footer

Powered by FluxBB