1819803 Members
2953 Online
109607 Solutions
New Discussion юеВ

Re: tar xvf question

 
SOLVED
Go to solution
Mike_Ca Li
Regular Advisor

tar xvf question

Is there a way to tar xvf only a specific directory from a tar file.
eg: tar cvf /directory
and here is the structure of /directory/subdir1/sdir1
Is it possible to untar only contents of sdir1?
What is best way to do it ?
Thanks.
5 REPLIES 5
Sean OB_1
Honored Contributor
Solution

Re: tar xvf question

Yes you can do that.

tar -xvf /path/to/tarfile /path/to/directory

G. Vrijhoeven
Honored Contributor

Re: tar xvf question

Hi,

To get only the subdir back you could go for:

The t to view.
tar tvf pipo.tar /directory/subdir1/sdir1
If it works
tar xff pipo.tar /directory/subdir1/sdir1

I can not test,

Gideon
Tim Nelson
Honored Contributor

Re: tar xvf question

yep

tar xvf tar_file /blah/dir_name/*

keep in mind whether the tar file is relative or absolute.

i.e. tar cvf /myfile.tar /mydirectory will untar as /mydirectory

To keep things flexable always create the tarfile relative.

i.e. tar cvf myfile.tar ./mydirectory

use tar vtf myfile.tar to list exactly how the tar file was created.

Luck
Tim Nelson
Honored Contributor

Re: tar xvf question

FYI, you cannot use a file spec when listing a tar file.

i.e. tar vtf myfile.tar /sub/directory/file*

wont work.
Robert-Jan Goossens
Honored Contributor

Re: tar xvf question

Hi,

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=17465

Take a look at Cheryl's advice.

Kind regards,
Robert-Jan