cancel
Showing results for 
Search instead for 
Did you mean: 

Tarring - Relative & Absolute

SOLVED
Go to solution
Vassilios
Frequent Advisor

Tarring - Relative & Absolute

Dear All,

You know when you tar a directory -- say

tar cvf - /opt/myfiles/ourfiles/everyonesfiles/ | compress > files.tar.Z

How do I un-tar this so that it untars this archive within a directory, so that it doesn't tar it from the absolute path.

Sorry.. im not sure if that was clear.. but you must get the picture?? If I untar all that.. it will untar everything in my root dir.

But, let's say I wanted it to be untarr'd in my /export/home/user_admin/ directory??

i.e. it would be /export/home/user_admin/opt/myfiles... etc..

What tar options are there to make sure I can do that?
Many thanks
5 REPLIES
James R. Ferguson
Acclaimed Contributor
Solution

Re: Tarring - Relative & Absolute

Hi:

You should use relative paths when making 'tar' archives. When confronted with extracting an archive made with absolute paths, use 'pax'.

For example, had I made a 'tar' archive of '/tmp/dummydir' with absolute paths but wanted to extract the contents into '/var/tmp' instead, I could do:

# tar -cvf /tmp/dummydir /tmp/myarchive
# cd /var/tmp;
# pax -r -s ',/tmp/,,' /tmp/myarchive

See the 'pax' manpages.

Regards!

...JRF...
Patrick Wallek
Honored Contributor

Re: Tarring - Relative & Absolute

Instead of using /opt/myfiles/ourfiles/ereryonesfiles in your tar statement do something like:

# cd/opt/myfiles/ourfiles

# tar cvf - everyonesfiles | compress > files.tar.Z

Then when you extract, the directory everyonesfiles will be created in the directory you are currently in.

If you need the whole /opt/myfiles.... structures, just omit the leading '/' and do:

# cd /
# tar cvf - opt/myfiles/ourfiles/everyonesfiles/ | compress > files.tar.Z
Vassilios
Frequent Advisor

Re: Tarring - Relative & Absolute

Thanks James & patrick.

Yes, patrick has a point, but the files are now tar'd and its too late to re-tar them again.
(It was a 1 GB tar file! and that was after compression!).

So, i think my best option is to learn about the pax command.

I'll read the man pages right now on pax, but please do not hesitate to save me time on this reading if you know what the syntax is for using the pax command to untar into a particular directory.

Thanks
Steven Schweda
Honored Contributor

Re: Tarring - Relative & Absolute

> [...] | compress [...]

Why not gzip?

> What tar options are there [...]

Which "tar" program are you using? GNU "tar"
offers more than the stock HP-UX "tar".

http://www.gnu.org/software/tar/
http://www.gnu.org/software/tar/manual/
http://www.gnu.org/software/tar/manual/tar.html#SEC108

A Forum search would probably have found all
this, too, of course.
Dennis Handly
Acclaimed Contributor

Re: Tarring - Relative & Absolute

>Patrick: Instead of using ...
# cd /opt/myfiles/ourfiles
# tar cvf - everyonesfiles | compress > files.tar.Z

You can combine the cd and tar into one and use gzip:
tar -cvf - -C /opt/myfiles/ourfiles everyonesfiles | gzip > files.tar.gz

>if you know what the syntax is for using the pax command to untar into a particular directory.

JRF showed you the syntax:
pax -r -s ',/tmp/,,' /tmp/myarchive

Or in your case:
zcat files.tar.Z | pax -r -v -s ',^/,,'
This will just remove the leading "/".
If you want to remove /opt/myfiles/ourfiles/everyonesfiles/, then:
zcat files.tar.Z | pax -r -v -s ',/opt/myfiles/ourfiles/everyonesfiles/,,'