1834163 Members
2489 Online
110064 Solutions
New Discussion

Re: tar

 
SOLVED
Go to solution
j773303
Super Advisor

tar

How to extract tar file to
assign directory?

for ex: tar -xvf test.tar ??
Hero
3 REPLIES 3
Michael Tully
Honored Contributor
Solution

Re: tar

You cannot extract tar to just any directory. If it has been created (the tar backup) with absolute path names it cannot be done.
If the backup was created as ./dir/file (example) then it can be extracted to any filesystem, but the directory hierarchy will also get created.
If you not sure run

# tar tvf test.tar
Anyone for a Mutiny ?
malay boy
Trusted Contributor

Re: tar

1) if you backup not using fullpath i.e

cd /home/malay
tar cvf malay.tar *

then you extract :

cd /tmp/malay
tar xvf malay.tar

all the file will be extracted to /tmp/malay

2) if backup using fullpath i.e

tar cvf malay.tar /home/malay

then on recover if you do i.e

cd /tmp/malay
tar xvf malay tar

you file will be restored in /home/malay instead of /tmp/malay

hope this help

regards
mB
There are three person in my team-Me ,myself and I.
Denver Osborn
Honored Contributor

Re: tar

If the archive was created using the full paths, you could still extract the archive to an alternate location.

# cp /sbin/tar /newpath
# cp tarfile.tar /newpath
# cd /newpath
# chroot ./ tar xvf tarfile.tar

You can then remove /newpath/tar and tarfile.tar

The files will be extracted relative to the new path. Instead of /mypath/myfile being extracted to the orignal location, it would now be /newpath/mypath/myfile

The short version to achieve the same results as above... use pax.

pax -r -p e -s '%^/%/newpath/%' -f tarfile.tar

-denver