SUMMARY:How do you untar a file with an absolute path name

From: Jon M Hayden (
Date: Wed Feb 18 1998 - 13:11:36 CST

Thanks to all who responded. Too many to thank separately:

Original question:
I have a tar file that I want to untar. The problem is that this file was
tar'd with the absolute pathname and I don't want to extract it with the
absolute pathname. Is there a way I can specify which directory I want these
files untar'd at? I think gnu tar can do this, but I don't have that on my
system right now.

Suggested Solutions:
1. A lot of people said get gtar. Unfortunately, I don't do a lot of work on
the system I needed to do this on and I don't have root access. Maybe I'll
install gtar in my home directory for future use.

2. There were also a lot of votes for the chroot command, but again I don't
have root access on this system.

Use the chroot command. It causes a command to be executed with a
different directory as root. So "chroot /tmp ls /usr" would return
a directory listing of /tmp/usr since /tmp is used as root. The
problem is that any commands you want to run with the chroot command
have to exist under the new root directory. In the above example, you
would have to first copy the ls command to /tmp. Also the command
needs to be the static linked version. Otherwise it won't find the
dynamic libraries.

This example is from the chroot man page:

          example# cp /usr/sbin/static/tar /tmp
          example# dd if=/dev/nrst0 | chroot /tmp tar xvf -

3. I had a couple suggestions to do links. Again, for me to do this, I would
of needed root access.
As far as I know you cannot do this with standard tar. My only suggestion
would be to create a link in the root directory.

eg if the top level name in the tar file is /tarfile

ln -s extract_dir /tarfile

This way the data is extracted into the place you want it.

4. Some people suggested "digital unix" options that I don't have on my Solaris

Try 'man tar' . You should find a -r or -R switch to strip off the leading
slash. On a Digital Unix system the flag is -s.

  P [Digital] Specifies the prefix that is to be stripped off of the
      filenames archived to or extracted from tape. (See also the s flag.)

  s [Digital] Tells tar to strip off any leading slashes from pathnames
      during extraction. This is useful when restoring a tape that was
      created on a system with a different file system structure. (See also
      the P flag.)

5. I was sent a perl script to do this, but I haven't had a chance to try it.
    I attached it for those of you that would like to try it.

What I did
I ended up just ftping the tar file to my system and extracting it with the
absolute pathname and then tar'd it back up the way I wanted it. Then ftp'd
back to the other system and untar'd it. It was about 300Meg in size so it took
a while.

Jon Hayden
Technical Support Engineer SUPPORT: 800/328-7739
Auspex Systems, Inc. DIRECT: 919/461-2215 FAX: 919/319-9910 PAGER: 800/391-4970

End of MIME message

This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:12:31 CDT