Operating System - HP-UX
1821063 Members
2529 Online
109631 Solutions
New Discussion юеВ

tar extraction to current working directory. Is it possible

 
SOLVED
Go to solution
Joe Profaizer
Super Advisor

tar extraction to current working directory. Is it possible

I have a tar file I created. I want to extract it into my current working directory, because I don't have the same mount point on the system that I'm extracting it to.
Can I do this?
8 REPLIES 8
Christopher McCray_1
Honored Contributor

Re: tar extraction to current working directory. Is it possible

Hello,

When you extract the archive, it will dump in your current location when you issue the command, so yes.

Hope this helps

Chris
It wasn't me!!!!
Ken Hubnik_2
Honored Contributor

Re: tar extraction to current working directory. Is it possible

It depends if the archive was create with absolute (full) path name or relative (./). Tar will lay done the archive in the current directory and depending on the above determines if full path or relative.
Darrell Allen
Honored Contributor

Re: tar extraction to current working directory. Is it possible

It's easy if you created the tar file with relative path names:
cd /directory_to_tar
tar cf output_tar_file files_or_dirs_to_tar

It's more difficult if you used absolute path names. You can use pax to extract this to a different directory.

Search the forums for "tar pax relative" and you'll find a number of threads. One is:
http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x38d6cf38d6bdd5118ff10090279cd0f9,00.html

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
James R. Ferguson
Acclaimed Contributor

Re: tar extraction to current working directory. Is it possible

Hi Joe:

Yes, you can do this using 'pax' ['tar's cousin]. For example, to extract into 'newdir' where the 'tar' was made with absolute paths to 'olddir', do:

# /sbin/pax -r -p e -s '%^/%/newdir/%' -f /dev/rmt/0m

...the above also preserves file timestamps and permissions. See the 'pax' man pages for more information.

Regards!

...JRF...
Darrell Allen
Honored Contributor

Re: tar extraction to current working directory. Is it possible

Sorry, I see I didn't complete my relative path names example:

cd /directory_to_tar
tar cf output_tar_file files_or_dirs_to_tar

cd /directory_to_restore_into
tar xf tarfile_created_above

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
S.K. Chan
Honored Contributor
Solution

Re: tar extraction to current working directory. Is it possible

Yes you can do this with pax .. take for example the tar file "/tmp/test.tar" which has a full abosolute path backup of say /opt/appsA and you want to extract all files under /opt/appsA and put those in /tmp/myapps instead. You would ..
# mkdir /tmp/myapps
# cd /tmp/myapps
# pax -r -s ',^/opt/appsA/,,' -f /tmp/test.tar -t
Elif Gius
Valued Contributor

Re: tar extraction to current working directory. Is it possible

If the 'tar' archive was created with absolute paths, then you can't use 'tar' to extract to a different directory

Instead you have to use pax...
John Palmer
Honored Contributor

Re: tar extraction to current working directory. Is it possible

If you created the tar with absolute pathnames then you could create one or more symbolic links pointing to where you want the files to be extracted.

Example, tar files backed up as /a/b/c/d/*
On extracting system, you want to extract to /x/y/z and don't have a /a...
mkdir -p /a/b/c
cd /a/b/c
ln -s /x/y/z d
tar ...

You can then remove the temporary directories /a...

Regards,
John