Just a very short note. It’s not so difficult, but I keep on forgetting the syntax. Here it is:
me@localhost$ tar cf - . | \
ssh user@otherhost 'cd dir; tar xf -'
Just a very short note. It’s not so difficult, but I keep on forgetting the syntax. Here it is:
me@localhost$ tar cf - . | \
ssh user@otherhost 'cd dir; tar xf -'
Why not just use scp -pr? E.g.: scp -pr . user@otherhost:dir/
If you need to do what you mentioned though and keep forgetting, why not create a function – e.g.:
tarssh()
{
tar cf – . | ssh $1 “cd $2 && tar xf -”
}
I didn’t test this, but something like this should work.
Note also that I changed a ; to a && so that it won’t untar into your home directory if it can’t cd into the directory.
I actually had a tar file that I wanted to extract in multiple home directories (some temporary guest accounts)…and just like to chain tools together with pipes
Tar also has a function to do ‘chdir’ for you, so you can invoke as
me@localhost $ tar cf – . | ssh user@otherhost tar -C dir -xf -
(note that you also do not need quotes for this)
I usually also add a ‘z’ to both tars, to use compression. Most pcs can decompress so fast that network throughput is still the bottleneck, even with compression.
Dirk,
Thanks, just what I was looking for.
uidzero
scp is sometimes not good becouse it can keep only file permisions without original file owners. tar can