LinuxQuestions.org
Visit Jeremy's Blog.
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 08-25-2004, 10:30 AM   #1
dgermann
Member
 
Registered: Aug 2004
Distribution: Ubuntu 8.04.1 desk; Red Hat 9.0 server
Posts: 331

Rep: Reputation: 30
Question Extract specific files from .tgz


Hi--

This is probably easy for you old pros, but could not find enough in the man pages to figure it out.

1. How can I extract specific files and directories from a tarball? What is the exact command line command I need to enter, please?

2. Is there any way to speed up the process with a huge .tgz file?

3. If I want to restore all the files and all the rights and dates and times, do I need to be logged into X as root, or can I do it as a normal user?

My secondary HDD failed yesterday. My backups are stored in .tgz files. After replacing the drive, I used Red Hat 9.0's File Roller to get many of the files I need.

Those were from a tarball that was 1.5 gigs. The one I am having difficulty with is one that is 13 gigs. File Roller takes about 45 minutes to read the file so I can tell it what to grab. Then I started the extraction last night at 10:20 pm and sat up all night with it (I had other files I needed to extract as soon as that was done, and a deadline to meet); it still was not done at 5:20 am this morning when I stopped it to get at least enough of the other files to meet my deadline.

In any event, I want to pull out a couple of directories, let's call them /doug2 and /doug3, and a couple of files, /foobar/sub1/file1, and /foobar/sub2/file2.

I tried this (if I remember straight after this all-nighter! ):
tar -xvf /backups/weekly.tgz doug2
and it reported that there was no such directory found in that .tgz file.
I tried /doug2 and same result. Yet File Roller displayed /doug2. So I must be doing something wrong. What's the key wording here, please?

So, to speed the process, would it make sense for me to unzip the file first and then only untar the directory I want? Will it even be visible once it is unzipped? Do something else? This file only took about 45 minutes to create; why should it take 7 1/2 hours + to extract?
 
Old 08-25-2004, 10:44 AM   #2
ugenn
Member
 
Registered: Apr 2002
Posts: 549

Rep: Reputation: 30
Re: Extract specific files from .tgz

Quote:
Originally posted by dgermann
Hi--

This is probably easy for you old pros, but could not find enough in the man pages to figure it out.

1. How can I extract specific files and directories from a tarball? What is the exact command line command I need to enter, please?


tar xzf foo.tar.gz path/to/file

2. Is there any way to speed up the process with a huge .tgz file?

Get faster hardware.

3. If I want to restore all the files and all the rights and dates and times, do I need to be logged into X as root, or can I do it as a normal user?

Dates and rights, yes. But not ownership / group.

My secondary HDD failed yesterday. My backups are stored in .tgz files. After replacing the drive, I used Red Hat 9.0's File Roller to get many of the files I need.

Those were from a tarball that was 1.5 gigs. The one I am having difficulty with is one that is 13 gigs. File Roller takes about 45 minutes to read the file so I can tell it what to grab. Then I started the extraction last night at 10:20 pm and sat up all night with it (I had other files I needed to extract as soon as that was done, and a deadline to meet); it still was not done at 5:20 am this morning when I stopped it to get at least enough of the other files to meet my deadline.

In any event, I want to pull out a couple of directories, let's call them /doug2 and /doug3, and a couple of files, /foobar/sub1/file1, and /foobar/sub2/file2.

I tried this (if I remember straight after this all-nighter! ):
tar -xvf /backups/weekly.tgz doug2
and it reported that there was no such directory found in that .tgz file.
I tried /doug2 and same result. Yet File Roller displayed /doug2. So I must be doing something wrong. What's the key wording here, please?


Try using relative paths instead of absolute paths.

So, to speed the process, would it make sense for me to unzip the file first and then only untar the directory I want? Will it even be visible once it is unzipped? Do something else? This file only took about 45 minutes to create; why should it take 7 1/2 hours + to extract?
Something is up with your hardware that makes writes slower than reads, I guess.
 
Old 08-25-2004, 11:02 AM   #3
littleking
Member
 
Registered: Jun 2003
Location: New Albany, OH
Posts: 190

Rep: Reputation: 30
tar -xvzf filename
 
Old 08-25-2004, 11:03 AM   #4
ugenn
Member
 
Registered: Apr 2002
Posts: 549

Rep: Reputation: 30
Forgot to add:

you can use the "t" option to tar to list tarballs. eg tar tzvf foo.tar.gz
 
Old 08-25-2004, 11:03 AM   #5
dgermann
Member
 
Registered: Aug 2004
Distribution: Ubuntu 8.04.1 desk; Red Hat 9.0 server
Posts: 331

Original Poster
Rep: Reputation: 30
ugenn--

Thanks for the quick reply!

I checked and I actually used tar -xvzf.

Quote:
Try using relative paths instead of absolute paths.
How is that done? Not sure the specific language to use....

You suggested--
Quote:
tar xzf foo.tar.gz path/to/file
I had used--
Quote:
tar -xvzf /backups/weekly.tgz doug2
So I need to remove the leading / in front of backups and I need to add /* after doug2, right? (normally I would just try these things, but it took it probably a half hour before it crapped out.

The hardware issue: I have a Celeron 2 ghz on an eMachines about 18 months old; the new drive is a Western Digital 120 gig, running as a slave with the jumper set to CS.

Thanks, ugenn!
 
Old 08-25-2004, 11:06 AM   #6
ugenn
Member
 
Registered: Apr 2002
Posts: 549

Rep: Reputation: 30
You don't add the trailing /* because the shell will expand it. just doug2 will do. Since doug2 is a dir, tar will pull all the subdirs under it out as well.
 
Old 08-25-2004, 11:39 AM   #7
dgermann
Member
 
Registered: Aug 2004
Distribution: Ubuntu 8.04.1 desk; Red Hat 9.0 server
Posts: 331

Original Poster
Rep: Reputation: 30
Thanks ugenn!

I looked again and I think I reversed the order of the archive filename and the directory I wanted in the command line.

That is great help! Thanks!
 
  


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
how to extract tgz Longinus Linux - Newbie 14 12-21-2015 04:30 AM
how to find a specific file over several *.tgz files eeyoree Slackware 6 08-09-2004 01:37 AM
how to extract file *.tgz vanhelsing Linux - Software 1 06-05-2004 07:07 AM
gunzip does not extract *.tgz nausicaa3000 AIX 6 02-07-2004 05:06 PM
how do i extract a .tgz ? lax2sman Linux - Networking 4 02-11-2002 05:40 PM


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