untar a single file from down in the tree


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers untar a single file from down in the tree
# 1  
Old 10-25-2011
[Solved] untar a single file from down in the tree

I have a tar file that I need to extract a single file to the current directory. The file I want to extract is located in the tar at the following path inside the tar file: repository/parts/SDCG.tgz

I use the following command to extract the file:
tar xf delivery.tar repository/parts/SDCG.tgz

It successfully extracts the file, but it puts in the current directory as repository/parts/SDCG.tgz. But what I want is just SDCG.tgz.

Is there a way for me to extract that single file to my current directory?

Thanks,
Robert
# 2  
Old 10-25-2011
You havent been searching the forum very much have you?

There are many threads e.g.
https://www.unix.com/unix-dummies-que...directory.html
# 3  
Old 10-25-2011
Ok, I looked a the post you pointed me to and I was able to get pax to work, but I didn't realize that pax works with .tar files but not .tgz files. When I first tried it on my .tgz file it gave all kinds of errors so I initially didn't think pax would be able to help me.

So I had to do a gunzip of my .tgz file.

I did the command: gunzip x.tgz
which replaced the file x.tgz with x.tar

The file I wanted to extract from the tar file was in path repository/parts/RDAP.tgz.

I did the following command:
Code:
pax -r -d repository/parts/RDAP.tgz -s'/repository\/parts\/RDAP.tgz//p' -f x.tar

this -s option allowed me to subtitute the path repository/parts/ with nothing. The file extracted to my current directory which is exactly what I wanted. Note that \/ is an escape sequence or /.

I am posting this in case someone else is looking to do the same thing.

Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.

Last edited by vbe; 10-25-2011 at 01:50 PM.. Reason: code tags
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to untar the below file?

I need to extract the below file. could you please let me know how to extract by using unix command. manfucture.today.1678.tar.gz (5 Replies)
Discussion started by: ramkumar15
5 Replies

2. UNIX for Dummies Questions & Answers

Not able to untar a file in HP UX!

Hi, I have been trying to untar this file hello.tar which consists of 3 files but nothing happens: eux750{root}# tar -xvf hello.tar x /hello, 8405 bytes, 17 tape blocks Why am I not able to see the untarred files.:wall: Thanks to help! (2 Replies)
Discussion started by: terminator
2 Replies

3. Shell Programming and Scripting

Not able to untar file

Hello Experts, I have requirement in which a file is present in the folder_test. In that folder there is file called Test.tar.gz.20111102. Now my requirement is i have to rename this file to someother format and untar it.... folder_test Test.tar.gz.20111102 I am using the below... (5 Replies)
Discussion started by: aks_1902
5 Replies

4. UNIX for Advanced & Expert Users

tar and untar the files using single line

Hi, i want tar the files from one location and untar it to other location using single line. Can any one help me zip and unzip using single line command. (2 Replies)
Discussion started by: venikathir
2 Replies

5. UNIX for Dummies Questions & Answers

untar a tar file

how can I untar a file without extracting it? sample: file.tar to file thanks, lara (1 Reply)
Discussion started by: lhareigh890
1 Replies

6. Shell Programming and Scripting

unzip single file and untar single file

Dear friends, My requirement below- 1] I have a zip file on unix server - ETL_Extracts_20100218175009.zip which is composed of various entity extracts namely... ENTITY1.txt, ENTITY2.txt, ENTITY3.txt etc.... How do I unzip only a single file ..say ENTITY2.txt from this zip file. CAn you... (2 Replies)
Discussion started by: sureshg_sampat
2 Replies

7. UNIX for Advanced & Expert Users

How do I untar file through an ssh session?

Hi All, How do I untar (tar xvf) a file through an ssh session? I have a tar file with "relative path names". I scp the file to a remote host:/tmp - no prob. But when I untar the file through ssh from a remote host it puts it in my "home directory" under the relative path - not in /tmp... (3 Replies)
Discussion started by: Joe McCaughan
3 Replies

8. UNIX and Linux Applications

unable to UNTAR a file

Hi frens, I have to install samba on UNIX box for that i have downloaded the samba file from netand now trying to untar that file and getting following error: # tar -xvf samba-3.0.28a.tar.gz UX:tar: ERROR: Directory checksum error even i checked many times by again downloading the file... (6 Replies)
Discussion started by: NIMISH AGARWAL
6 Replies

9. UNIX for Dummies Questions & Answers

untar to a specified file

I have file1.tar and want to untar it under /server/file2. If I do tar -xvf file1.tar, the files will be deployed under file1. How to specify the destination folder?? thx (3 Replies)
Discussion started by: melanie_pfefer
3 Replies

10. Shell Programming and Scripting

unTar a specific file from remote

During tar, the command used is tar cvf - * | remsh system_name dd of=/dev/rmt/0m bs=10k To untar all, we used remsh system_name "dd if=/dev/rmt/0m ibs=10k" | tar xvf - Question? How to untar a specific file from remote? Thanks alot... (2 Replies)
Discussion started by: gelbvonn
2 Replies
Login or Register to Ask a Question