1751975 Members
4734 Online
108784 Solutions
New Discussion юеВ

Re: relitive tar | gzip

 
SOLVED
Go to solution
rleon
Regular Advisor

relitive tar | gzip

Here is what I have but it is absolute and over writes the file into the original directory when the file is untared,

tar -cf - /path/to/myfile.txt | gzip -9 > /archive/myfile.tgz

I know I can do cd /path/to and do my tar and my gzip and it will be relative.

But I was wondering if there was a way to tar it as a relative tar file without having to cd into the directory. But doing it from the tar command.

Thanks


5 REPLIES 5
Bill Hassell
Honored Contributor
Solution

Re: relitive tar | gzip

No, not with the standard tar command. The path that you give is exactly what is stored. You can use pax to restore files from a tar archive into a different directory:

pax -rvf /tmp/backup.tar

This extracts files to the current directory.You can add one or more -n to extract more filenames


Bill Hassell, sysadmin
Steven Schweda
Honored Contributor

Re: relitive tar | gzip

> [...] without having to cd into the
> directory. [...]

Who cares? How hard is it to do it with a
"cd" command?

( cd /path ; tar -cf - to/myfile.txt ) | \
gzip -9 > /archive/myfile.tgz

Where's the problem?

Or use GNU "tar", which has a "-C = dir"
("--directory=dir") option:

http://www.gnu.org/software/tar/manual/html_node/Option-Summary.html#SEC42
Dennis Handly
Acclaimed Contributor

Re: relitive tar | gzip

>if there was a way to tar it as a relative tar file without having to cd into the directory. But doing it from the tar command.

Read tar(1)?
tar -cf - -C /path/to myfile.txt | gzip -9 > /archive/myfile.tgz

Unfortunately this is one good thing about tar that isn't in pax(1). But pax has -s.

>Bill: not with the standard tar command.

I think you misinterpreted PBSG's question.

>You can use pax to restore files from a tar archive into a different directory:

Yes, you need to use -s.

> Steven: How hard is it to do it with a
"cd" command?

It was hard enough they added -C to tar. :-)
Steven Schweda
Honored Contributor

Re: relitive tar | gzip

> It was hard enough they added -C to tar. :-)

"-C" has the advantage that you can use it
more than once in the list of files. I can't
say that I've ever wanted to do that with
"tar", but I have with mkisofs, so I can
imagine situations where it might be handy.
rleon
Regular Advisor

Re: relitive tar | gzip

thanks !