LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-18-2003, 10:32 AM   #1
phil1076
Member
 
Registered: Oct 2001
Location: Grand Cayman
Distribution: RH 9.0
Posts: 96

Rep: Reputation: 16
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.
 
Old 12-18-2003, 10:37 AM   #2
jkobrien
Member
 
Registered: Jun 2003
Location: Dublin, Ireland
Distribution: Slackware, LFS, Ubuntu, RedHat, Slamd64
Posts: 507

Rep: Reputation: 30
You could put them in a loop.

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

John
 
Old 12-18-2003, 12:14 PM   #3
WindowsBurner
Member
 
Registered: Nov 2003
Location: In chaos
Distribution: OpenSuse
Posts: 293

Rep: Reputation: 30
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.
 
Old 12-18-2003, 12:19 PM   #4
jkobrien
Member
 
Registered: Jun 2003
Location: Dublin, Ireland
Distribution: Slackware, LFS, Ubuntu, RedHat, Slamd64
Posts: 507

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

'tcsh'

John
 
Old 12-18-2003, 12:23 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914
How about

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


Shell-independent ;)


Cheers,
Tink
 
Old 12-18-2003, 12:25 PM   #6
WindowsBurner
Member
 
Registered: Nov 2003
Location: In chaos
Distribution: OpenSuse
Posts: 293

Rep: Reputation: 30
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.
 
Old 12-18-2003, 12:28 PM   #7
WindowsBurner
Member
 
Registered: Nov 2003
Location: In chaos
Distribution: OpenSuse
Posts: 293

Rep: Reputation: 30
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.
 
Old 12-18-2003, 12:30 PM   #8
jkobrien
Member
 
Registered: Jun 2003
Location: Dublin, Ireland
Distribution: Slackware, LFS, Ubuntu, RedHat, Slamd64
Posts: 507

Rep: Reputation: 30
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
 
Old 12-18-2003, 12:31 PM   #9
WindowsBurner
Member
 
Registered: Nov 2003
Location: In chaos
Distribution: OpenSuse
Posts: 293

Rep: Reputation: 30
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.

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

Last edited by WindowsBurner; 12-18-2003 at 12:34 PM.
 
Old 12-18-2003, 12:42 PM   #10
jkobrien
Member
 
Registered: Jun 2003
Location: Dublin, Ireland
Distribution: Slackware, LFS, Ubuntu, RedHat, Slamd64
Posts: 507

Rep: Reputation: 30
Excellent!

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

John
 
Old 12-18-2003, 12:43 PM   #11
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914
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
 
Old 12-18-2003, 12:45 PM   #12
WindowsBurner
Member
 
Registered: Nov 2003
Location: In chaos
Distribution: OpenSuse
Posts: 293

Rep: Reputation: 30
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.
 
Old 12-18-2003, 12:51 PM   #13
WindowsBurner
Member
 
Registered: Nov 2003
Location: In chaos
Distribution: OpenSuse
Posts: 293

Rep: Reputation: 30
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.
 
Old 12-18-2003, 12:53 PM   #14
jkobrien
Member
 
Registered: Jun 2003
Location: Dublin, Ireland
Distribution: Slackware, LFS, Ubuntu, RedHat, Slamd64
Posts: 507

Rep: Reputation: 30
You're forgetting '*.tgz'!

John
 
Old 12-18-2003, 12:54 PM   #15
WindowsBurner
Member
 
Registered: Nov 2003
Location: In chaos
Distribution: OpenSuse
Posts: 293

Rep: Reputation: 30
Thanks John thats a pretty important one.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
tarring a dd stream john8675309 Linux - Software 1 04-22-2005 03:04 PM
set password when bzipping/tarring/gzipping alice95089 Linux - Software 14 01-03-2005 03:09 PM
Issue tarring data Johnny Mac Linux - Newbie 5 11-12-2004 02:58 PM
Help I need help tarring multiple files in multiple directories VisionZ Linux - Newbie 28 03-25-2004 05:25 PM
Tar with --newer option tarring all dirs jlangelier Linux - Newbie 0 07-09-2003 12:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:39 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration