tar: extract single file to different filepath


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting tar: extract single file to different filepath
# 1  
Old 02-28-2008
Question tar: extract single file to different filepath

Hi,

This is my first post here - I'm hoping I can get some help! I have searched these forums and othersand not getting anything that works.

I am trying to extract a single file from a tar archive to a diffierent location than it will default to.

For example my tar log shows me ...

Code:
a /scratch2/no_archive/nlthoa/input_files/EGIS_EXPORTS/ 0K
a /scratch2/no_archive/nlthoa/input_files/EGIS_EXPORTS/README.txt 4K
a /scratch2/no_archive/nlthoa/input_files/EGIS_EXPORTS/multi_runs/ 0K
a /scratch2/no_archive/nlthoa/input_files/EGIS_EXPORTS/multi_runs/PB0012.run 2K

... and I want to extract this file ...
Code:
/scratch2/no_archive/nlthoa/input_files/EGIS_EXPORTS/multi_runs/PB0012.run

... to ...

Code:
/home/nlthoa/tmp

So how can I do that?

The system will not allow me to recreate the original file path, and I do not want the entire contents either.

I am working in Solaris 8 (I think)
Code:
uname -a
SunOS xxxxxx-x-xxxxxx 5.8 Generic_117350-51 sun4u sparc SUNW,Sun-Fire-V440

Any help appreciated!

Thanks,
lil'
# 2  
Old 02-28-2008
Unfortunatly, this might e tough to get round. The problem is that when the tarball was created, it was done so using absolute paths (generally a bad thing to do in tar).

Different versions of tar handle absolute paths differently, some ignore it on restore (which is sort of what you want), some ignore it during creation and do it relative instead. Some honour it one way, some both.

I would suggest grabbing a copy of gnu tar (it's a bit different from Sun tar) and trying that. You might find it'll be able to extract your file relative to your homedir instead.
# 3  
Old 02-29-2008
A collegue found a work around - he created a link file in the top level directory (as root) that pointed to some other place, and when I ran the noraml untar, all the data came out as I wanted it.

I agve up trying to get just one file out of the tarball.

Thought I'd just post this for the sake of completness.
# 4  
Old 02-29-2008
We have worked on some application which was meant to uncompress tar files. Due to security reasons (hopefully you know about tar bombs, don't you?) data extraction (and decompression when input files were *.tar.gz) was made using some open-source JAVA module that can handle *.tar packages. And what is more important - this module can skip the paths.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Tar extract Z file

I was looking at this tutorial for tar extract Z file. Is there a reason why this did not work? I checked my man pages and it had a -Z option. tar -xZvf /opt/Nimsoft/nimldr.tar.Z tar (child): compress: Cannot exec: No such file or directory tar (child): Error is not recoverable: exiting now... (2 Replies)
Discussion started by: cokedude
2 Replies

2. Shell Programming and Scripting

Extract filepath names between two strings

OS : Fedora Linux 26 Shell : bash I have a file with around 5000 lines like below. file /usr/share/icons/Papirus/16x16/actions/papirus-icon-theme-20180501-1.noarch conflicts with file ... file /usr/share/icons/Papirus/16x16/actions/align-horizontal-left-to-anchor.svg conflicts between... (7 Replies)
Discussion started by: John K
7 Replies

3. Shell Programming and Scripting

Extract a single file from a tar file to another directory

Hi, I need to extract a single file from a tar file to another directory. So far I have this: This one extract a single file to same directory: tar -xvf filename.tar ./file.txt I tried this but its not working tar -xvf filename.tar /home/dir ./file.txt or this: (6 Replies)
Discussion started by: erin00
6 Replies

4. UNIX for Dummies Questions & Answers

Do I need to extract the entire tar file to confirm the tar folder is fine?

I would like to confirm my file.tar is been tar-ed correctly before I remove them. But I have very limited disc space to untar it. Can I just do the listing instead of actual extract it? Can I say confirm folder integrity if the listing is sucessful without problem? tar tvf file1.tar ... (1 Reply)
Discussion started by: vivien_chu
1 Replies

5. UNIX for Dummies Questions & Answers

Restoring a single file from a group of files using tar

Hello I take a backup using the following command on Solaris 9 tar cvf /dev/rmt/0n data the data volume contains a number of files say a, b, c , d ... etc Now I want to restore only one file (eg b) from the data volume. When I issue the command tar xvf /dev/rmt/0n data/b... (1 Reply)
Discussion started by: rahmantanko
1 Replies

6. UNIX for Advanced & Expert Users

How to extract a particular file in tar.Z format

Hi , I need to extarct only a particulay files from the tar.Z. ie i need to extract one.txt from test.tar.Z. The test.tar.Z may contain lot of file and folders. Please help me to extract particular file to some location. Regards, Kalai. (1 Reply)
Discussion started by: kalpeer
1 Replies

7. UNIX for Dummies Questions & Answers

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... (7 Replies)
Discussion started by: icefish
7 Replies

8. UNIX for Advanced & Expert Users

how to unzip and extract tar file in single command

In order to save diskspace and avoid of disk full during unzip then extract the tar file is there any tar unzip command would unzip and extract tar at the same time (test123.tar.gz) thank in advance (6 Replies)
Discussion started by: darkrainbow
6 Replies

9. Shell Programming and Scripting

extract one file form .tar.gz without uncompressing .tar.gz file

hi all, kindly help me how to extract one file form .tar.gz without uncompressing .tar.gz file. thanks in advance bali (2 Replies)
Discussion started by: balireddy_77
2 Replies

10. UNIX for Dummies Questions & Answers

cant extract files from a tar file

hi everyone i have a tar file which was in AIX box. its 300mb. i cant untar in windowsxp home. I just get an empty folder with no files when i extract. i dont get any bad header or any such error. i am using IZARC which is a freeware. Not sure if i should try winzip or winrar. any help (2 Replies)
Discussion started by: bryan
2 Replies
Login or Register to Ask a Question