tar ---- extracting files to different directory than the default one!

tar ---- extracting files to different directory than the default one!

Post by Raqueeb Hass » Fri, 28 Feb 2003 06:38:38



Hello,

I don't know, but is there anyway to extract files from a tar file to
a different directory than the default one? If I'm not wrong, possibly
I did it before ... (I got a bad memory).

Like ... I did backup my users home directory ...

#tar cvf /backup/backup.tar /export/home

now, I want to exctact the files in different folder rather that in
/export. How do I do it, please?

I'm sorry for posting it to wrong ng, but hey ... I'm little desperate
:-(

raqueeb hassan
augusta, ga

 
 
 

tar ---- extracting files to different directory than the default one!

Post by Barry Margoli » Fri, 28 Feb 2003 06:48:38




>I don't know, but is there anyway to extract files from a tar file to
>a different directory than the default one? If I'm not wrong, possibly
>I did it before ... (I got a bad memory).

>Like ... I did backup my users home directory ...

>#tar cvf /backup/backup.tar /export/home

The best thing to do is *not* use an absolute path when making the tar file
in the first place:

cd /export/home
tar cvf /backup/backup.tar .

Quote:

>now, I want to exctact the files in different folder rather that in
>/export. How do I do it, please?

GNU tar has an option to ignore a leading slash in the pathnames in the
archive, so it will extract the files to a subdirectory export/home in the
current directory.

But if you're using traditional Unix tar, you're screwed.

--

Genuity Managed Services, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

tar ---- extracting files to different directory than the default one!

Post by Magnu » Fri, 28 Feb 2003 07:13:55



> The best thing to do is *not* use an absolute path when making the
> tar file in the first place:

> cd /export/home
> tar cvf /backup/backup.tar .

Or, sticking with tar we could: tar cvf /backup/backup.tar -C /export/home .

- Magnus

 
 
 

tar ---- extracting files to different directory than the default one!

Post by Lee Har » Fri, 28 Feb 2003 09:52:27



Quote:> Hello,

> I don't know, but is there anyway to extract files from a tar file to
> a different directory than the default one? If I'm not wrong, possibly
> I did it before ... (I got a bad memory).

> Like ... I did backup my users home directory ...

> #tar cvf /backup/backup.tar /export/home

> now, I want to exctact the files in different folder rather that in
> /export. How do I do it, please?

> I'm sorry for posting it to wrong ng, but hey ... I'm little desperate
>:-(

You can create a chroot environment and unpack inside of that:

mkdir unpack
mkdir unpack/usr
mkdir unpack/usr/bin
cp `which tcsh` unpack
cp `which tar` unpack
cp `which gzip` unpack/usr/bin
cp backup.tgz unpack
su
chroot unpack /tcsh
./tar zxf backup.tgz
exit

Hope this helps.

 
 
 

tar ---- extracting files to different directory than the default one!

Post by rnich.. » Fri, 28 Feb 2003 15:20:31



:Hello,
:
:I don't know, but is there anyway to extract files from a tar file to
:a different directory than the default one? If I'm not wrong, possibly
:I did it before ... (I got a bad memory).
:
:Like ... I did backup my users home directory ...
:
:#tar cvf /backup/backup.tar /export/home
:
:now, I want to exctact the files in different folder rather that in
:/export. How do I do it, please?

GNU tar will, by default, delete the leading '/' from absolute
pathnames, both when creating an archive and when extracting from it.
If your version of tar doesn't do that, one possibility would be to
bring the system down to single-user mode, rename the existing
/export/home to something else, extract from your tar archive, and then
move everything back where it belongs.

It's also possible to set up a chroot environment for running tar, but
doing that is a bit of a PITA.  You'll need to have tar and any
libraries it needs within that environment.  The archive itself can be
piped in on stdin.

  # ldd /bin/tar
        libpthread.so.0 => /lib/libpthread.so.0 (0x40025000)
        librt.so.1 => /lib/librt.so.1 (0x4003c000)
        libc.so.6 => /lib/libc.so.6 (0x4004e000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
  # mkdir -p /tmp/tdir/lib /tmp/tdir/bin
  # cp /lib/libpthread.so.0 /lib/librt.so.1 /lib/libc.so.6 /lib/ld-linux.so.2 /tmp/tdir/lib
  # cp /bin/tar /tmp/tdir/bin
  # chroot /tmp/tdir /bin/tar -xvf - </backup/backup.tar

Your files will now be in /tmp/tdir/export/home.

--

 
 
 

tar ---- extracting files to different directory than the default one!

Post by Raqueeb Hass » Sat, 01 Mar 2003 01:39:35


Thanks all of you for the help.

raqueeb hassan
augusta, ga

 
 
 

1. tar question: how do I extract some files without extracting directories

For example, if I have foo.tar.gz consisting of:

foo/
    bar/
      baz/
        file1.png

What (GNU) tar options do I have to use to extract the file 'file1.png'
to ~/tmp without the directory hierarchy 'foo/bar/baz'?

Something like:

   $ tar zx ~/tmp/file1.png f foo.tar.gz   #This does not work...

Should produce:

~/tmp/
    file1.png

Any thoughts?

TIA,

    Erik.

2. Linux Doom music player, version 0.9

3. tar question: how do I extract some files without extracting directories.

4. IOMEGA products

5. how to direct solaris tar to extract to different directory?

6. Can't run X on MkLinux pre-R1

7. How to extract files from a tar archive under a different name

8. HELP! Can't get to login prompt on install

9. Extracting TAR Files in a specific Directory

10. extract specific directory from tar file

11. How to extract only one file from a tar archive?

12. tar files from different directories