The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Single line file editing command? gator76 Shell Programming and Scripting 1 04-03-2008 11:09 AM
tar: extract single file to different filepath littleIdiot Shell Programming and Scripting 3 02-29-2008 09:41 AM
how to unzip and extract tar file in single command darkrainbow UNIX for Advanced & Expert Users 6 02-28-2008 08:18 PM
extract bulk emails into a single flat file Amruta Pitkar Shell Programming and Scripting 1 01-21-2007 06:37 PM
Extract first file only from ls command prekida Shell Programming and Scripting 4 07-26-2005 05:46 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-01-2008
icefish icefish is offline
Registered User
  
 

Join Date: May 2007
Posts: 16
tar command help -- extract single file

Hi,
I want to view/display the contents of one file in tar file.
For example if the tar file is sam.tar.gz and one of the file inside is E1.txt, how do i view the contents of this E1.txt file.

Olso if I want to extract the E1.txt file only from sam.tar.gz how can i do that.

Thanks in advance.
  #2 (permalink)  
Old 07-01-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,289
To print the files use "zcat". But I know no option for it to cat only a single file of the archive.

To list the contents of an archive, use:
Code:
tar tvf my.tar
# or
tar tvzf my.tar.gz
To extract the file "singlefile.dat" of the archive:
Code:
tar xvzf my.tar.gz singlefile.dat
  #3 (permalink)  
Old 07-01-2008
icefish icefish is offline
Registered User
  
 

Join Date: May 2007
Posts: 16
Thanks.

One more question
Where will the singlefile.dat be extracted. I dont want to overwrite any existing file.
  #4 (permalink)  
Old 07-01-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,289
Usually in your pwd where you currently are. If done non-interactive via script and cronjob for example, you should do a cd to be sure, you are at the place in the filesystem, where you want to be.
I avoid to tar stuff with a leading slash. So I can always move to a tmp directory and extract there to avoid overwriting.
It's always a bad surprise if some &*!@$! (to have it in comic speech censorship) creates an archive with absolute path. That can cause an unwanted update of your data heh.
  #5 (permalink)  
Old 07-01-2008
icefish icefish is offline
Registered User
  
 

Join Date: May 2007
Posts: 16
Actually I tared the file with absolute path like the command below
tar -cvf sam.tar /home/sam

Now I want to extract /home/sam/E1.txt in sam.tar to /home/ram

Please help.
  #6 (permalink)  
Old 07-01-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,289
As I said, please tar without absolute paths. You can get more problems of this than you'd like. Just create some tmp subdirectory close to your destination, uncompress/untar it there and move it to where it belongs.
  #7 (permalink)  
Old 07-01-2008
spirtle spirtle is offline
Registered User
  
 

Join Date: Jun 2008
Location: Scotland
Posts: 150
Gnu tar helpfully removes any leading / in a path to avoid the potential problems that zaxxon describes -- unless specifically told to keep it with -P. If your tar doesn't do this, you can only do
Code:
tar -xf sam.tar /home/sam/E1.txt
cp /home/sam/E1.txt /home/ram
i.e. you will create E1.txt with the absolute rather than a relative path.
tar -x can only extract from the archive what you put in there; use -t (as zaxxon said) to see what that is.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:16 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0