tarring absolute paths for relative untar

tarring absolute paths for relative untar

Post by Terrence Monroe Branno » Fri, 01 Jun 2001 08:05:52



I have a command which outputs to STDOUT a bunch of absolute paths to
some files of interest:

/tmp/x
/tmp/y/z/g/x.txt
/tmp/er/wsdf/sddd.doc

I would like to tar all of these files up, but have them untar in
relative fashion. ie,

tmp/x
tmp/y/z/g/x.txt
tmp/er/wsdf/sddd.doc

I am using Solaris tar

--
Terrence Brannon

 
 
 

tarring absolute paths for relative untar

Post by Michael Nguye » Fri, 01 Jun 2001 10:16:07


One way is to tar it up from within /tmp

$ cd /tmp
$ tar cf whatever.tar *


> I have a command which outputs to STDOUT a bunch of absolute paths to
> some files of interest:

> /tmp/x
> /tmp/y/z/g/x.txt
> /tmp/er/wsdf/sddd.doc

> I would like to tar all of these files up, but have them untar in
> relative fashion. ie,

> tmp/x
> tmp/y/z/g/x.txt
> tmp/er/wsdf/sddd.doc

> I am using Solaris tar

> --
> Terrence Brannon


 
 
 

tarring absolute paths for relative untar

Post by Frederick Bruckm » Fri, 01 Jun 2001 11:14:10




Quote:> I have a command which outputs to STDOUT a bunch of absolute paths to
> some files of interest:

> /tmp/x
> /tmp/y/z/g/x.txt
> /tmp/er/wsdf/sddd.doc

> I would like to tar all of these files up, but have them untar in
> relative fashion. ie,

> tmp/x
> tmp/y/z/g/x.txt
> tmp/er/wsdf/sddd.doc

> I am using Solaris tar

How about this?

  cd /
  COMMAND | cut -c 2- | xargs tar cf - | gzip -9 - > ~/foo.tar.gz

--

Frederick

 
 
 

tarring absolute paths for relative untar

Post by D. Bircha » Sun, 03 Jun 2001 16:53:02



Quote:> I have a command which outputs to STDOUT a bunch of absolute paths to
> some files of interest:

> /tmp/x
> /tmp/y/z/g/x.txt
> /tmp/er/wsdf/sddd.doc

> I would like to tar all of these files up, but have them untar in
> relative fashion. ie,

> tmp/x
> tmp/y/z/g/x.txt
> tmp/er/wsdf/sddd.doc

Hmmm.  If they're really all under the same tree all nice like
that, you should be able to something like this:

cd /
tar -cf file.tar `(command) |cut -c2- |xargs`

The 'cut -c2-' gets rid of the leading slash, the 'xargs' with no
arguments sticks 'em all onto one line.

If they're *not* all under the same tree, or you need the tree to
be different - say, for example, you've got:

/u01/staging1/docs/file1.txt
/u02/staging2/docs/file2.txt

and you want to have them both untar in:

/u03/staging3/docs/

Then you get into doing something like:

cd /u01/staging1/
tar -cf /u03/staging3/file.tar -C /u01/staging1 `(command) |xargs`
cd /u02/staging2/
tar -rf /u03/staging3/file.tar -C /u02/staging2 `(command) |xargs`

where 'command' in this case outputs filenames with a relative
path, based on the path passed with the -C flag.

Hope this is vaguely helpful.

-Dan

--
This address expires.  Take out the hostname if your reply bounces.
Read http://dan.scream.org/pay4spam.html before you send ads to me.
This address may not be distributed unless this notice is included.
Visit http://dbirchall.epinions.com/user-dbirchall for my opinions.

 
 
 

tarring absolute paths for relative untar

Post by Juergen P. Mei » Sun, 03 Jun 2001 17:57:20




>> I have a command which outputs to STDOUT a bunch of absolute paths to
>> some files of interest:

>> /tmp/x
>> /tmp/y/z/g/x.txt
>> /tmp/er/wsdf/sddd.doc

>> I would like to tar all of these files up, but have them untar in
>> relative fashion. ie,

>> tmp/x
>> tmp/y/z/g/x.txt
>> tmp/er/wsdf/sddd.doc

This task is possible with chroot(1), you just have to (temporarily)
setup the nessecary files in your destination directory. e.g.:

mkdir /dest/dir (where you wish to extract the above files)
mkdir /dest/dir/dev /dest/dir/lib
ldd `which tar` <- ln (not -s) or cp all required libs to /dest/dir/lib
cp -p `which tar` /dest/dir/
cp mytarfile.tar /dest/dir/
create a rudimentary set of devicefiles in /dest/dir/dev/ required
for tar to operate (use truss or strace on a normal tar to find out
which /dev/ entries it uses)
then chroot /dest/dir ./tar xf ./mytarfile.tar

you probably need to be uid=0 if your chroot cmd is not suid-root.

juergen

--

 
 
 

tarring absolute paths for relative untar

Post by Geoff Clar » Thu, 07 Jun 2001 22:19:28



>How about this?
>  cd /
>  COMMAND | cut -c 2- | xargs tar cf - | gzip -9 - > ~/foo.tar.gz

1. You forgot to include "-d /" in the cut command.

2. xargs will*up if any of the filenames contain whitespace or
quoting characters.

3. Extracting the files from foo.tar.gz cannot be done with a simple
gunzip | tar, since it will likely contain several concatenated tar
archives.  (tar would stop at the end of the first archive.)

Since the OP was using Solaris, he could switch to using pax or cpio
to write the tar archive without the need for xargs:

  cd / && COMMAND | cut -d / -c 2- | pax -w -x ustar | gzip ...

  cd / && COMMAND | cut -d / -c 2- | cpio -oHustar | gzip ...

--


 
 
 

1. Make relative tar path absolute at extraction

Is there any way that I can tar, for example, /tmp/usr/local/apache2
and when it is extracted, force it to /usr/local/apache2? I know I can
cd to /tmp and cvf on usr/local/apache2 from there, but that requires
being in / when extracting the tar later. The people who extract these
tars are often in their own home directory, so the files don't go
where they need to. Is there anything I can do when I make a
relative-pathed tar to make the extraction location absolute?

2. link to mimetype

3. Relative path to Absolute path

4. look at this

5. Relative path to Absolute Path

6. Project created by Anjuta wizard, autogetn.sh problem.

7. Symbolic Links - Absolute Paths to Relative Paths

8. Terminal 3151 (emulation)

9. C: get absolute path to a file from relative path

10. Add an absolute path prefix only to relative paths

11. Untar a file with bsolute paths to a relative location ( HELP PLEASE)

12. How to untar an absolut tarred file to relative destination?

13. How to convert a relative path into an absolute one?