Operating System - HP-UX
1758842 Members
3233 Online
108876 Solutions
New Discussion юеВ

How to extract files into a perticular directory from a tar file

 
yatin
Frequent Advisor

How to extract files into a perticular directory from a tar file

How to extract files into a perticular directory from a tar file
14 REPLIES 14
Sanjay Kumar Suri
Honored Contributor

Re: How to extract files into a perticular directory from a tar file

cd /dir1
tar xvf backup.tar

sks
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
Shaikh Imran
Honored Contributor

Re: How to extract files into a perticular directory from a tar file

hi,

Go to the directory where you want to extract
the tar file &
use:
#tar -xvf file.tar
where file.tar is present in that directory.

Regards,
I'll sleep when i am dead.
yatin
Frequent Advisor

Re: How to extract files into a perticular directory from a tar file

Cant i do that with a single command like tar -C(in Linux)
Ravi_8
Honored Contributor

Re: How to extract files into a perticular directory from a tar file

Hi,

assume that your tar file is /tmp/a.tar

you need to extract that in directory /usr/ravi

#mkdir /usr/ravi
#cd /usr/ravi
#tar xvf /tmp/a.tar .

never give up
Sanjay Kumar Suri
Honored Contributor

Re: How to extract files into a perticular directory from a tar file

Although there is option -C in man tar which states:

-C directory causes tar to perform a chdir() to directory (see chdir(2)). Subsequent file and -C directory arguments are relative to directory. This allows multiple
directories not related by a close or common parent to be archived using short relative path names.

However I couldn't succeed in using this. I am trying.

sks
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
Muthukumar_5
Honored Contributor

Re: How to extract files into a perticular directory from a tar file

Hai,

tar with -C option is used to do operation on a file located in another directory and make tar operations on that directory with going to that.

pwd /
tar file is located over /home/test/test.tar
then,

[/] tar -C /home/test -xvf /home/test/test.tar

It will archieve files over at /home/test/test directory

This operation is same to hp-ux and linux too.

Regards
Muthu
Easy to suggest when don't know about the problem!
yatin
Frequent Advisor

Re: How to extract files into a perticular directory from a tar file

ta -C doesnt work as it works in Linux
Mei Jiao
Respected Contributor

Re: How to extract files into a perticular directory from a tar file

I tried the tar with -C as well, it doesn't work as what you want it to be.

Please cd into the directory and do the 'tar -xvf ' then.
Muthukumar_5
Honored Contributor

Re: How to extract files into a perticular directory from a tar file

This is the error (all) will get when you try tar -C on linux as,

tar: You must specify one of the `-Acdtrux' options
Try `tar --help' for more information.

-C is used to change the directory, as
-C, --directory=DIR change to directory DIR

So it is used to reduce to change directory to operate the tar.
It is same as,
cd /home/test;tar xvf test.tar
tar -C /home/test -xvf /home/test/test.tar

Regards
Muthukumar.


Easy to suggest when don't know about the problem!