Operating System - HP-UX
1830048 Members
22077 Online
109998 Solutions
New Discussion

extract one file or folder for a tar file

 
SOLVED
Go to solution
ran_li
Regular Advisor

extract one file or folder for a tar file

Hello,

I need tips on how to extract one file or one folder from a tar file.

Thanks in advance.

tar tvf testfile.tar
home/user1/data/testdata1
home/user1/data/testdata2
home/user2/patch/testpatch1
home/user2/patch/testpatch2

can I use tar to get file testdata1 or the folder user1?

5 REPLIES 5
Jonathan Fife
Honored Contributor
Solution

Re: extract one file or folder for a tar file

It's as simple as it sounds:

tar -xvf testfile.tar home/user1/data/testdata1

or

tar -xvf testfile.tar /home/user1
Decay is inherent in all compounded things. Strive on with diligence
James R. Ferguson
Acclaimed Contributor

Re: extract one file or folder for a tar file

Hi:

Aside from the fact that you have your answer, please note that it's not "good form" to use that other OS term 'folder'. It's a 'directory' in Unix!

Regards!

...JRF...
ran_li
Regular Advisor

Re: extract one file or folder for a tar file

Thanks for the tips and clarification.

Regards!
Cem Tugrul
Esteemed Contributor

Re: extract one file or folder for a tar file

TAR

Things to remember about tar:

* tar is, for the most part, platform generic (ie: a tar tape created on
a SUN machine can usually be read by an HPUX machine). However, if the
platforms are far removed from each other (ie: SunOS 4.x and HPUX
11.0), then reading the tape may be impossible.

Command Description

tar cvf /dev/rmt/0m /etc/hosts backup one file

tar cvf /dev/rmt/0m (file1) (file2) backup file1 and file2

tar tvf /dev/rmt/0m verify contents of tape

tar xvf /dev/rmt/0m restore entire tape

tar xvf /dev/rmt/0m (file) restore one file

tar tf /dev/rmt/0m | grep swp | xargs restore all files that contain
tar xvf /dev/rmt/0m the string swp

Good Luck,
Our greatest duty in this life is to help others. And please, if you can't
ran_li
Regular Advisor

Re: extract one file or folder for a tar file

thanks for the details.

Best regards!