Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 10-01-2003, 07:28 AM   #1
Registered: Aug 2003
Posts: 55

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


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 07:33 AM.
Old 10-01-2003, 07:49 AM   #2
Registered: Sep 2003
Location: Denmark
Distribution: FreeBSD
Posts: 110

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

Old 10-01-2003, 07:57 AM   #3
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, 06:07 AM   #4
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
#tar zxvf *.tar.gz
#tar zxvf filename.tgz
Old 10-02-2003, 06:37 AM   #5
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.

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

Rep: Reputation: 0
This worked for me


for a in `ls -1 *.tar.gz`; do tar -zxvf $a; done
Old 07-22-2009, 10:03 AM   #7
Registered: Feb 2008
Location: coevorden
Distribution: mepis, ubuntu server ed. Debian. Redhat. Fedora, centos, LFS
Posts: 211

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, 06:13 PM   #8
LQ Newbie
Registered: Jan 2017
Posts: 3

Rep: Reputation: Disabled
find -name "*tar.gz" -exec tar xvzf '{}' \;
Old 03-24-2017, 03:17 AM   #9
Senior Member
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 18.1 MATE
Posts: 2,450

Rep: Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843
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, 12:58 PM   #10
LQ Addict
Registered: Dec 2013
Posts: 5,330

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


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 10:51 AM
untar a list of tar files? Rotwang Linux - General 6 10-10-2006 01:34 PM
Getting problem when untar the .tar.gz file? ramakumard77 Linux - General 2 11-29-2004 11:15 AM
Bash script (untar *.tar files and then cd to the untared dir) k0ljat Linux - Newbie 2 12-30-2003 05:57 AM
Untar filename.tar.tar Dr.Swing Linux - Newbie 12 09-27-2002 07:10 AM

All times are GMT -5. The time now is 04:07 AM.

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