LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 06-19-2002, 01:18 PM   #1
MasterC
LQ Guru
 
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu ; CentOS ; Raspbian
Posts: 12,613

Rep: Reputation: 69
Uncompress several tarballs with 1 command


I have been trying to uncompress several .tar.gz and .tgz tarballs from a single directory (example /tarballs) into another directory (example /usr/share/untarballs) with one command:

tar xvzf /tarballs/* /usr/share/untarballs

But have had no luck.

Any ideas or suggestions?

Thanks
 
Old 06-20-2002, 02:54 AM   #2
Mik
Senior Member
 
Registered: Dec 2001
Location: The Netherlands
Distribution: Ubuntu
Posts: 1,316

Rep: Reputation: 47
Well there is two reasons why that command won't work. The first is because you can't specify a directory to extract to like that. If you run it like you have then it will try to extract the /usr/share/untarballs file from the archive which is obviously not there. Just add the C switch to allow you to extract to a certain directory.
Ex:

tar xvzCf /usr/share/untarballs /tarballs/file.tar.gz

The second problem is however with the wildcard. The string /tarballs/* is not passed to the tar command. But instead the shell first interprets the wildcard and then passes it on to the tar command. So in your case the command which gets run would be something like:

tar xvzf /tarballs/1.tar.gz /tarballs/2.tar.gz /usr/share/untarballs

In the case of the above command it will try to extract the files 2.tar.gz and untarballs from the archive 1.tar.gz which will fail. So you've got to repeatedly run the tar command passing it only one tar file ech time. You could use a for loop for that but you said you where looking for one command line. So maybe something like this would work for you:

ls /tarballs/*.tar.gz | xargs -n 1 tar xvzCf /usr/share/untarballs

The ls command command will make a list of all the tar.gz files. This is then passed on to xargs who will run the tar command passing it 1 parameter each time (-n 1). I know it's 2 commands with a pipe but I don't think you can get it shorter then that.
 
Old 06-20-2002, 03:03 AM   #3
MasterC
LQ Guru
 
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu ; CentOS ; Raspbian
Posts: 12,613

Original Poster
Rep: Reputation: 69
Mik I think I will hook up a T1 line to your house. Thanks, yet again.
 
  


Reply



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
uncompress .Z command not found in FC2 acer_peri Linux - Software 2 05-31-2004 03:45 AM
Uncompress command BajaNick Linux - Software 7 10-05-2003 02:20 PM
Problems with uncompress TPupAZ Linux - Software 2 09-30-2003 01:54 PM
What to do when no uncompress... sx10 Linux - General 3 08-21-2002 11:42 AM
How do you uncompress something? wings9191 Linux - Newbie 8 02-12-2002 11:36 PM

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

All times are GMT -5. The time now is 10:22 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
Open Source Consulting | Domain Registration