How do I untar file through an ssh session?

Hi All,

How do I untar (tar xvf) a file through an ssh session?

I have a tar file with "relative path names".
I scp the file to a remote host:/tmp - no prob.
But when I untar the file through ssh from a remote host
it puts it in my "home directory" under the relative path -
not in /tmp where I really want it to go.

Here it is:

$ set -o vi
$ tar tvf test.tar
drwxr-xr-x 992 205 0 May 23 15:14:44 2008 holdingArea/
drwxr-xr-x 992 205 0 May 23 15:14:42 2008 holdingArea/ccmig_1_00/
drwxrwxrwx 992 205 0 May 23 15:14:44 2008 holdingArea/stage/
drwxrwxrwx 992 205 0 May 23 15:14:54 2008 holdingArea/stage/ccmig_1_00/
drwxr-xr-x 992 205 0 May 23 15:14:53 2008 holdingArea/stage/ccmig_1_00/system/
-rwxrwxr-x 992 205 7 May 23 15:14:55 2008 holdingArea/stage/ccmig_1_00/system/system1.txt
-rwxrwxr-x 992 205 7 May 23 15:14:55 2008 holdingArea/stage/ccmig_1_00/system/system2.txt
-rwxrwxr-x 992 205 7 May 23 15:14:55 2008 holdingArea/stage/ccmig_1_00/system/system3.txt
-rwxrwxr-x 992 205 7 May 23 15:14:55 2008 holdingArea/stage/ccmig_1_00/system/system4.txt
drwxr-xr-x 992 205 0 May 23 15:14:53 2008 holdingArea/stage/ccmig_1_00/utils/
-rwxrwxr-x 992 205 7 May 23 15:14:55 2008 holdingArea/stage/ccmig_1_00/utils/utils1.txt
-rwxrwxr-x 992 205 7 May 23 15:14:55 2008 holdingArea/stage/ccmig_1_00/utils/utils2.txt
-rwxrwxr-x 992 205 7 May 23 15:14:55 2008 holdingArea/stage/ccmig_1_00/utils/utils3.txt
-rwxrwxr-x 992 205 7 May 23 15:14:55 2008 holdingArea/stage/ccmig_1_00/utils/utils4.txt
drwxr-xr-x 992 205 0 May 23 15:14:54 2008 holdingArea/stage/ccmig_1_00/config/
drwxr-xr-x 992 205 0 May 23 15:14:54 2008 holdingArea/stage/ccmig_1_00/config/config1/
-rwxrwxr-x 992 205 7 May 23 15:14:56 2008 holdingArea/stage/ccmig_1_00/config/config1/config11.txt
-rwxrwxr-x 992 205 7 May 23 15:14:56 2008 holdingArea/stage/ccmig_1_00/config/config1/config12.txt
-rwxrwxr-x 992 205 7 May 23 15:14:56 2008 holdingArea/stage/ccmig_1_00/config/config1/config13.txt
-rwxrwxr-x 992 205 7 May 23 15:14:56 2008 holdingArea/stage/ccmig_1_00/config/config1/config14.txt
drwxr-xr-x 992 205 0 May 23 15:14:54 2008 holdingArea/stage/ccmig_1_00/config/config1/config2/
-rwxrwxr-x 992 205 7 May 23 15:14:56 2008 holdingArea/stage/ccmig_1_00/config/config1/config2/config21.txt
-rwxrwxr-x 992 205 7 May 23 15:14:57 2008 holdingArea/stage/ccmig_1_00/config/config1/config2/config31/config314.txt
. . . .
$ whoami
framrodjones
$ scp test.tar remotehost:/tmp
test.tar 100% 40KB 40.0KB/s 00:00
$
$ ssh remotehost tar xvf /tmp/test.tar
x holdingArea
x holdingArea/ccmig_1_00
x holdingArea/stage
x holdingArea/stage/ccmig_1_00
x holdingArea/stage/ccmig_1_00/system
x holdingArea/stage/ccmig_1_00/system/system1.txt, 7 bytes, 1 tape blocks
x holdingArea/stage/ccmig_1_00/system/system2.txt, 7 bytes, 1 tape blocks
x holdingArea/stage/ccmig_1_00/system/system3.txt, 7 bytes, 1 tape blocks
x holdingArea/stage/ccmig_1_00/system/system4.txt, 7 bytes, 1 tape blocks
x holdingArea/stage/ccmig_1_00/utils
x holdingArea/stage/ccmig_1_00/utils/utils1.txt, 7 bytes, 1 tape blocks
x holdingArea/stage/ccmig_1_00/utils/utils2.txt, 7 bytes, 1 tape blocks
x holdingArea/stage/ccmig_1_00/utils/utils3.txt, 7 bytes, 1 tape blocks
x holdingArea/stage/ccmig_1_00/utils/utils4.txt, 7 bytes, 1 tape blocks
x holdingArea/stage/ccmig_1_00/config
x holdingArea/stage/ccmig_1_00/config/config1
x holdingArea/stage/ccmig_1_00/config/config1/config11.txt, 7 bytes, 1 tape blocks
x holdingArea/stage/ccmig_1_00/config/config1/config12.txt, 7 bytes, 1 tape blocks
x holdingArea/stage/ccmig_1_00/config/config1/config13.txt, 7 bytes, 1 tape blocks
x holdingArea/stage/ccmig_1_00/config/config1/config14.txt, 7 bytes, 1 tape blocks
x holdingArea/stage/ccmig_1_00/config/config1/config2
x holdingArea/stage/ccmig_1_00/config/config1/config2/config21.txt, 7 bytes, 1 tape blocks
x holdingArea/stage/ccmig_1_00/config/config1/config2/config22.txt, 7 bytes, 1 tape blocks
x holdingArea/stage/ccmig_1_00/config/config1/config2/config23.txt, 7 bytes, 1 tape blocks
. . . .
$

OK - looks good. But when I login to remotehost and cd /tmp there is
no holdingArea there.

If I cd ~framrodjones - bingo - the holdingArea is there.
But that's not where I want it. How to I untar the test.tar so that it installs
in the directory where I scp'd it?

Thanks, FramRodJones

ssh remotehost (cd /tmp ; tar xvf test.tar)

or

ssh remotehost "cd tmp ; tar xvf test.tar"

depending on your shell.

Better yet though, why not stream it? That way you don't need to scp it first.

cat test.tar | ssh remotehost "cd tmp ; tar xvf -"

Taking the example even further:

cd /where/the/original/data/is ; tar -cf - . | ssh remotehost "cd tmp ; tar xvf -"

Totally cool.
I chose this: cat test.tar | ssh remotehost "cd tmp ; tar xvf -"

Works great! Thank you!:smiley:

hope you know when you ssh / telnet / rlogin as a specific user to a box, you are taken to that particular users home directory. In your case, you were taken to your home directory in the remore box and tar was extracting at the location you were at, while issuing the tar command :wink: