Copying Directories with SSH

Copying data is something every administrator does.  A single file or directory file can be copied with a single command.  Moving information from one system to another needs a bit more work, but it needn’t be a pain.

The ssh command can be used to copy data from one Unix system to another.    Here is an example for HP-UX, but it works on Linux too.  A directory, called /var/opt/ignite, is copied from the system “pluto” to another machine called “jupiter”.

pluto:/# cd /var/opt
pluto:/var/opt# tar cf - ignite | ssh -l root jupiter "cd /var/opt ; tar -xvf -"

As each file is transferred, its name is written to standard out.  Remove the final “v” from the command line, and the copy will work silently.

There are other ways to do it, of course.  The files could be tarred into a single file, transferred with sftp, and then unpacked on the target system.  That is a longer process,  and it requires extra disk space on both the source and target systems.  The above pipeline does it in one jump.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.