LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 10-01-2003, 08:28 AM   #1
zoomzoom
Member
 
Registered: Aug 2003
Posts: 55

Rep: Reputation: 15
How to untar all tar-files in a directory?


Hi

Although its a somehow stupid question:

can anyone give me the right tar command to extract all file of a directory? i tried 'tar -xzvf *.tar.gz' and many others but none worked... (i also couldnt find what i need in the manpage)

Thank you

Last edited by zoomzoom; 10-01-2003 at 08:33 AM.
 
Old 10-01-2003, 08:49 AM   #2
WiZaC
Member
 
Registered: Sep 2003
Location: Denmark
Distribution: FreeBSD
Posts: 110

Rep: Reputation: 15
Examples:
tar -cf archive.tar foo bar # Create archive.tar from files foo and bar.
tar -tvf archive.tar # List all files in archive.tar verbosely.
tar -xf archive.tar # Extract all files from archive.tar.

WiZaC
 
Old 10-01-2003, 08:57 AM   #3
jogar
LQ Newbie
 
Registered: Sep 2003
Location: Yorktown, VA
Distribution: Mandrake 10
Posts: 8

Rep: Reputation: 0
Try (in bash):

for a in `ls -1 *.tar.gz`; do gzip -dc $a | tar xf -; done
 
Old 10-02-2003, 07:07 AM   #4
farhanagri
LQ Newbie
 
Registered: Sep 2003
Location: Bangladesh
Distribution: as i have 3 pc i use slackware redhat and suse linux
Posts: 3

Rep: Reputation: 0
try
#tar zxvf *.tar.gz
#tar zxvf filename.tgz
 
Old 10-02-2003, 07:37 AM   #5
yapp
Member
 
Registered: Apr 2003
Location: Netherlands
Distribution: SuSE (before: Gentoo, Slackware)
Posts: 613

Rep: Reputation: 30
extract one tar.gz:
* tar zxf filename.tar.gz

extract a certain file:
* tar zxf filename.tar.gz requested-files..

That's why your *.tar.gz doesn't work.
If you type "echo *" you'll see what every shell does, and why tar doesn't see the "*.tar.gz" you've typed.

Code:
for filename in *.tar.gz
do
  tar zxf $filename
done
 
Old 05-27-2007, 04:50 PM   #6
sthneed
LQ Newbie
 
Registered: May 2007
Posts: 1

Rep: Reputation: 0
This worked for me

bash:

for a in `ls -1 *.tar.gz`; do tar -zxvf $a; done
 
Old 07-22-2009, 11:03 AM   #7
R03L
Member
 
Registered: Feb 2008
Location: Emmer-compascuum
Distribution: redhat* debian* arch* slack*
Posts: 216

Rep: Reputation: 31
for i in *.tar.gz

for i in *.tar.gz; do echo working on $i; tar xvzf $i ; done

works for me!
 
Old 03-23-2017, 07:13 PM   #8
lindsayad
LQ Newbie
 
Registered: Jan 2017
Posts: 3

Rep: Reputation: Disabled
find -name "*tar.gz" -exec tar xvzf '{}' \;
 
Old 03-24-2017, 04:17 AM   #9
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
Quote:
Originally Posted by lindsayad View Post
find -name "*tar.gz" -exec tar xvzf '{}' \;
This will not only find all the tar files in a directory, but also those in all its subdirectories.

You should use find's -maxdepth 1 option to restrict the search to a single directory.
 
Old 03-24-2017, 01:58 PM   #10
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
... and now let's put it back to sleep for another 8 years!

it's not even a very interesting topic (lots of similar threads across multiple boards).
 
Old 05-09-2017, 11:58 AM   #11
bobbytables
LQ Newbie
 
Registered: May 2017
Location: Parent's House
Distribution: Ubuntu 16.04
Posts: 2

Rep: Reputation: Disabled
From above, single quotes didn't work for me.


Code:
for a in $(ls -1 *.tar.gz); do tar -zxvf $a; done
 
Old 05-09-2017, 12:07 PM   #12
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
Quote:
Originally Posted by bobbytables View Post
From above, single quotes didn't work for me.

Code:
for a in $(ls -1 *.tar.gz); do tar -zxvf $a; done
Those weren't single quotes, they were backticks.
 
1 members found this post helpful.
Old 05-09-2017, 12:33 PM   #13
bobbytables
LQ Newbie
 
Registered: May 2017
Location: Parent's House
Distribution: Ubuntu 16.04
Posts: 2

Rep: Reputation: Disabled
Oh whoops, thanks for pointing that out.
 
Old 05-09-2017, 12:52 PM   #14
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
Quote:
Originally Posted by bobbytables View Post
Oh whoops, thanks for pointing that out.
No problem. You added another solution into the mix.

Welcome to LQ.
 
1 members found this post helpful.
  


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
Whats the command to untar files that end in .tar.bz2? BaZiL Linux - Newbie 3 06-20-2007 11:51 AM
untar a list of tar files? Rotwang Linux - General 6 10-10-2006 02:34 PM
Getting problem when untar the .tar.gz file? ramakumard77 Linux - General 2 11-29-2004 12:15 PM
Bash script (untar *.tar files and then cd to the untared dir) k0ljat Linux - Newbie 2 12-30-2003 06:57 AM
Untar filename.tar.tar Dr.Swing Linux - Newbie 12 09-27-2002 08:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:07 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