LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   un-tarring multiple files (https://www.linuxquestions.org/questions/linux-general-1/un-tarring-multiple-files-126937/)

phil1076 12-18-2003 10:32 AM

un-tarring multiple files
 
If I have 10 tarballs in the current directory and I want to un-tar them all, how do I do it?

I've tried: tar-xvf *.tar and it does not work.

Thanks in advance for your help.

jkobrien 12-18-2003 10:37 AM

You could put them in a loop.

foreach TAR (*.tar)
tar -xvf $TAR
end

John

WindowsBurner 12-18-2003 12:14 PM

I've had the same problem and I tried your loop but it doesnt work.
It says there is en error near unexpected token ( .

Any suggestions?I'm gonna keep loooking.

jkobrien 12-18-2003 12:19 PM

You're probably using the bash shell. Sorry, that should have occurred to me. Try again in the t-shell.

'tcsh'

John

Tinkster 12-18-2003 12:23 PM

How about

find <your start directory> -iname "*.tar" -exec tar xvf {} \;


Shell-independent ;)


Cheers,
Tink

WindowsBurner 12-18-2003 12:25 PM

I fixed it so the loop works

#!/bin/bash
for TAR in "*.tar"; do
echo $TAR
done

but I still cant untar mulitple files it gives me the following error when I run ./script.sh chmoded 777 :

tar : tar2.tar: not found in archive
tar : tar2.tar: not found in archive
tar : Error exit delayed from previous errors

My files are as follows : tar1.tar tar2.tar tar3.tar.

I'll try yours with the tcsh shell.

WindowsBurner 12-18-2003 12:28 PM

Yours works tink and so just yours jk when i use the TCSH shell....but I'm still gonna see if I cant get it working with the Bash shell.

jkobrien 12-18-2003 12:30 PM

Well, Tink's answer IS working with the Bash shell. I guess you mean you want to crack the loop approach?

One thing about the 'find' method is that it will also untar anything in subdirectories as well. There's a switch to stop the find descending into subdirectories though. Can't remember what it is, just wanted to post a caveat.

John

WindowsBurner 12-18-2003 12:31 PM

XDDD
I figured it out :)

#!/bin/bash
for TAR in *.tar; do
echo $TAR
done

This untars the files correctly....I almost had it before but I had to delete the quotation marks. Another linux problem down 999 left. :D

I'm now gonna make it so it will decompress gzips and bzips also.

jkobrien 12-18-2003 12:42 PM

Excellent!

Not so much 999 problems left, as 999 ways to do something!

John

Tinkster 12-18-2003 12:43 PM

Quote:

One thing about the 'find' method is that it will also untar anything in subdirectories as well. There's a switch to stop the find descending into subdirectories though. Can't remember what it is, just wanted to post a caveat.
find <your start directory> -maxdepth 1 -iname "*.tar" -exec tar xvf {} \;

;)


Cheers,
Tink

WindowsBurner 12-18-2003 12:45 PM

True 999 ways to do something. In one day i learned :
How to create a second super user.
How to change the login message : Welcome to Linux 2.2.4 (tty1) to what ever I want.
How to use the for statement in bash.

Here is my script now but now it doesnt do anything ??

#!/bin/sh


for TAR in *.tar*; do
case "$TAR" in
[*.tar.gz] ) tar -xzvf $TAR;;
[*.tar.bz] ) tar -xjvf $TAR;;
[*.tar] ) tar -xvf $TAR;;
esac
done


my dir structure is : tar1.tar tar2.tar tar3.tar test.tar.gz

Any help with that would be appreciated becuase this is the first time ive used the case statement.

WindowsBurner 12-18-2003 12:51 PM

Got it sort of figure out :

#!/bin/sh


for TAR in *.tar*; do
case "$TAR" in
*.tar.gz ) tar -xzvf $TAR;;
*.tar.bz ) tar -xjvf $TAR;;
*.tar ) tar -xvf $TAR;;
esac
done

Now I get an error about gzip complaing that one of the files are not in gzip format.
It does decompress everything now though.Now all I got to do is figure out that error message.

Hope this helped the guy who started the thread.

jkobrien 12-18-2003 12:53 PM

You're forgetting '*.tgz'! :)

John

WindowsBurner 12-18-2003 12:54 PM

Thanks John thats a pretty important one.


All times are GMT -5. The time now is 01:22 PM.