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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
10-01-2003, 08:28 AM
|
#1
|
Member
Registered: Aug 2003
Posts: 55
Rep:
|
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.
|
|
|
10-01-2003, 08:49 AM
|
#2
|
Member
Registered: Sep 2003
Location: Denmark
Distribution: FreeBSD
Posts: 110
Rep:
|
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
|
|
|
10-01-2003, 08:57 AM
|
#3
|
LQ Newbie
Registered: Sep 2003
Location: Yorktown, VA
Distribution: Mandrake 10
Posts: 8
Rep:
|
Try (in bash):
for a in `ls -1 *.tar.gz`; do gzip -dc $a | tar xf -; done
|
|
|
10-02-2003, 07: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:
|
try
#tar zxvf *.tar.gz
#tar zxvf filename.tgz
|
|
|
10-02-2003, 07:37 AM
|
#5
|
Member
Registered: Apr 2003
Location: Netherlands
Distribution: SuSE (before: Gentoo, Slackware)
Posts: 613
Rep:
|
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
|
|
|
05-27-2007, 04:50 PM
|
#6
|
LQ Newbie
Registered: May 2007
Posts: 1
Rep:
|
This worked for me
bash:
for a in `ls -1 *.tar.gz`; do tar -zxvf $a; done
|
|
|
07-22-2009, 11:03 AM
|
#7
|
Member
Registered: Feb 2008
Location: Emmer-compascuum
Distribution: redhat* debian* arch* slack*
Posts: 216
Rep:
|
for i in *.tar.gz
for i in *.tar.gz; do echo working on $i; tar xvzf $i ; done
works for me!
|
|
|
03-23-2017, 07:13 PM
|
#8
|
LQ Newbie
Registered: Jan 2017
Posts: 3
Rep:
|
find -name "*tar.gz" -exec tar xvzf '{}' \;
|
|
|
03-24-2017, 04:17 AM
|
#9
|
LQ Guru
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
|
Quote:
Originally Posted by lindsayad
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.
|
|
|
03-24-2017, 01:58 PM
|
#10
|
LQ Addict
Registered: Dec 2013
Posts: 19,872
|
... 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).
|
|
|
05-09-2017, 11:58 AM
|
#11
|
LQ Newbie
Registered: May 2017
Location: Parent's House
Distribution: Ubuntu 16.04
Posts: 2
Rep:
|
From above, single quotes didn't work for me.
Code:
for a in $(ls -1 *.tar.gz); do tar -zxvf $a; done
|
|
|
05-09-2017, 12:07 PM
|
#12
|
LQ Guru
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
|
Quote:
Originally Posted by bobbytables
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.
|
05-09-2017, 12:33 PM
|
#13
|
LQ Newbie
Registered: May 2017
Location: Parent's House
Distribution: Ubuntu 16.04
Posts: 2
Rep:
|
Oh whoops, thanks for pointing that out.
|
|
|
05-09-2017, 12:52 PM
|
#14
|
LQ Guru
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
|
Quote:
Originally Posted by bobbytables
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.
|
All times are GMT -5. The time now is 03:07 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|