Operating System - HP-UX
1752529 Members
4226 Online
108788 Solutions
New Discussion юеВ

Re: how untar the file in different directory

 
rajesh73
Super Advisor

how untar the file in different directory

how to untar the tar file in different directory
Example
$/tmp
$ls -l
$test.tar test
$tar -xvf test.tar -C /opt

this is possible or not
4 REPLIES 4
James R. Ferguson
Acclaimed Contributor

Re: how untar the file in different directory

Hi:

If you have a 'tar' archive that was made with absolute paths, use 'pax' to extract it to a different directory:

# pax -r -s '|/tmp/|/opt/|' -f test.tar

Regards!

...JRF...
Steven Schweda
Honored Contributor

Re: how untar the file in different directory

> this is possible or not

You're right?


What's in "test.tar"?

tar tfv test.tar

> [...] use 'pax' [...]

Or GNU "tar".

Or, you could look at any of the dozens of
similar threads in this Forum, where this
question has been answered before.
Dennis Handly
Acclaimed Contributor

Re: how untar the file in different directory

>tar -xvf test.tar -C /opt

The -C option is only valid when writing to an archive.
Raj D.
Honored Contributor

Re: how untar the file in different directory

Rajesh,

If you have taken the tar backup without the first "/" you can extract it to any other directory,

- What is the output of # tar -tvf test.tar


For Example: (Taking a backup of /etc )
# cd /
# tar -cvf etc_backup.tar etc


Extracting above /etc backup to /mydir/ :
# cd /mydir/
# tar -xvf /etc_backup.tar .
# it will create the etc directory under the current directory and extract all file & directgoirs of etc backup. So the path will be /mydir/etc/ .....


Hope this helps,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "