LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-06-2005, 05:26 AM   #1
int21h
LQ Newbie
 
Registered: Dec 2005
Distribution: Ubuntu 7.04
Posts: 24

Rep: Reputation: 15
how to extract mutiple tar.gz


How do I extract multiple tar.gz files? I have morethan 30 tar.gz files and i want to extract them all at once.
i've try this tar xvfz *.tar.gz but its not work.

whats wrong with my command?
 
Old 12-06-2005, 05:30 AM   #2
Ynot Irucrem
Member
 
Registered: Apr 2005
Location: Perth, Western Australia
Distribution: Debian
Posts: 233

Rep: Reputation: 30
you need to specify the "f" switch last in the list, because it tells tar that the next argument is the file to extract.
 
Old 12-06-2005, 05:34 AM   #3
T.Hsu
Member
 
Registered: Jan 2005
Posts: 178

Rep: Reputation: 31
IIRC tar xvfz should work. You could use for statement

for i in *.tar.gz
do tar zxvf $i
done
 
Old 12-06-2005, 06:11 AM   #4
int21h
LQ Newbie
 
Registered: Dec 2005
Distribution: Ubuntu 7.04
Posts: 24

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Ynot Irucrem
you need to specify the "f" switch last in the list, because it tells tar that the next argument is the file to extract.
please tell me the step by step procedure or an example, im totally newbie. tnx...


++++++++++++++++++++++++++++++++++++++++

int21h:/home/int21h/test# for i in *.tar.gz
> do tar zxvf $i
> done
tar: *.tar.gz: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error exit delayed from previous errors
int21h:/home/int21h/test#

i have tried but same problem.

any solution please.
 
Old 12-06-2005, 06:14 AM   #5
T.Hsu
Member
 
Registered: Jan 2005
Posts: 178

Rep: Reputation: 31
Are those tar.gz files in the current directory?
 
Old 12-06-2005, 06:15 AM   #6
Ynot Irucrem
Member
 
Registered: Apr 2005
Location: Perth, Western Australia
Distribution: Debian
Posts: 233

Rep: Reputation: 30
try
Code:
for i in `ls *.tar.gz`
do tar zxvf $i
done
note: those are backticks (next to [1], same key as ~) in the first line, not apostrophes.
 
Old 12-06-2005, 11:51 AM   #7
enemorales
Member
 
Registered: Jul 2004
Location: Santiago, Chile
Distribution: Ubuntu
Posts: 410

Rep: Reputation: 31
Shouldn't be

Code:
for i in *tar.gz; do
tar xvfz $i
done
?? (i.e. there is a ";" before the do keyword)

(same for the "ls" solution)
 
Old 12-06-2005, 11:41 PM   #8
int21h
LQ Newbie
 
Registered: Dec 2005
Distribution: Ubuntu 7.04
Posts: 24

Original Poster
Rep: Reputation: 15
i tried but same output.
here is the output, take a look

int21h@int21h:~/test$ ls -l
total 2072
-rwxr-xr-x 1 int21h int21h 92160 2005-12-06 14:20 GDM-9nome-Darmis.tar
-rwxr-xr-x 1 int21h int21h 1013760 2005-12-06 14:26 GDM-Angel.tar
-rwxr-xr-x 1 int21h int21h 307200 2005-12-06 14:17 GDM-AproachOne.tar
-rwxr-xr-x 1 int21h int21h 686080 2005-12-06 14:26 GDM-Blueish.tar

int21h@int21h:~/test$ for i in *tar.gz; do tar xvfz $i; done
tar: *tar.gz: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error exit delayed from previous errors
int21h@int21h:~/test$
 
Old 12-06-2005, 11:45 PM   #9
int21h
LQ Newbie
 
Registered: Dec 2005
Distribution: Ubuntu 7.04
Posts: 24

Original Poster
Rep: Reputation: 15
why is it that the * character is not recognized as a wild card of tar command?
 
Old 12-06-2005, 11:46 PM   #10
jrdioko
Member
 
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944

Rep: Reputation: 30
Those are tar files, not .tar.gz files. How about "for i in `ls *.tar` ..."
 
Old 12-06-2005, 11:50 PM   #11
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 52
Quote:
Originally Posted by int21h
i tried but same output.
here is the output, take a look

int21h@int21h:~/test$ ls -l
total 2072
-rwxr-xr-x 1 int21h int21h 92160 2005-12-06 14:20 GDM-9nome-Darmis.tar
-rwxr-xr-x 1 int21h int21h 1013760 2005-12-06 14:26 GDM-Angel.tar
-rwxr-xr-x 1 int21h int21h 307200 2005-12-06 14:17 GDM-AproachOne.tar
-rwxr-xr-x 1 int21h int21h 686080 2005-12-06 14:26 GDM-Blueish.tar

int21h@int21h:~/test$ for i in *tar.gz; do tar xvfz $i; done
tar: *tar.gz: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error exit delayed from previous errors
int21h@int21h:~/test$
I don't see any tar.gz file. Only .tar files.
try
Code:
for i in *.tar; do tar -xvf $i; done
 
Old 12-06-2005, 11:59 PM   #12
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 52
Quote:
Originally Posted by enemorales
Shouldn't be

Code:
for i in *tar.gz; do
tar xvfz $i
done
?? (i.e. there is a ";" before the do keyword)

(same for the "ls" solution)
It's the same thing. Instead of putting ; you can always press enter (new line). The opposite is not correct.

so basically you may write this in one line:
Code:
for i in *tar.gz; do tar xvfz $i; done
or
Code:
for i in *tar.gz
do tar xvfz $i 
done
or
Code:
for i in *tar.gz
do 
    tar xvfz $i 
done
it's just different coding styles. Personally I prefer to either write it all in one line if the for loop is small or write it like you did, with the "do" in the same line with "for".
 
Old 12-07-2005, 04:24 AM   #13
enemorales
Member
 
Registered: Jul 2004
Location: Santiago, Chile
Distribution: Ubuntu
Posts: 410

Rep: Reputation: 31
Good to know you can just press enter (I always put the ";", because I thought it may possible to have a file named "do", so it may be necessary to really know where the lists ends. I assume that filename cannot have "\n" inside). Thanks!
 
Old 12-07-2005, 05:34 AM   #14
Ynot Irucrem
Member
 
Registered: Apr 2005
Location: Perth, Western Australia
Distribution: Debian
Posts: 233

Rep: Reputation: 30
It is possible to have a filename with "\n" inside, but the shell knows that, and escapes it. the only character not allowable in a filename is null.
 
Old 12-08-2005, 07:58 AM   #15
int21h
LQ Newbie
 
Registered: Dec 2005
Distribution: Ubuntu 7.04
Posts: 24

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jrdioko
Those are tar files, not .tar.gz files. How about "for i in `ls *.tar` ..."

sorry i paste the wrong one. that is the list from my test folder. but from my tar.gz folder it is.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
can not extract the tar.gz file sharad durgawad Linux - Software 3 10-05-2005 03:41 AM
using tar to extract properly xushi Slackware 9 03-05-2005 10:10 AM
extract .tar.bz2 EcceVery Debian 3 11-24-2004 01:39 PM
tar extract fails dgermann Linux - Newbie 8 08-28-2004 12:26 PM
Choosing where to extract tar.gz Arclite Linux - Software 14 08-14-2003 04:57 PM


All times are GMT -5. The time now is 02:14 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration