Copying files: Difference between revisions

From DISI
Jump to navigation Jump to search
(Created page with "To copy from the machine you are on tar czf - dir1 dir2 dir3 | ssh tbalius@sgehead.bkslab.org "tar xzf - -C path/for/new/files " To copy from a remote machine to the machi...")
 
No edit summary
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
One way to copy files to and from a machine is as follows:
To copy from the machine you are on
To copy from the machine you are on


  tar czf - dir1 dir2 dir3 | ssh tbalius@sgehead.bkslab.org "tar xzf - -C path/for/new/files "
  tar czf - dir1 dir2 dir3 | ssh tbalius@sgehead.bkslab.org "tar xzf - -C path/for/new/files "


To copy from a remote machine to the machine you are on
ssh tbalius@sgehead.uoft.bkslab.org "cd path/to/dir/you/want ; tar czf - diryouwant1 diryouwant2 " | tar xzf - -C where/it/goes/locally
This has advantages that it does not copy symbolic links. 
It also compresses the data while copying


To copy from a remote machine to the machine you are on
Clear?
 
ssh tbalius@sgehead.uoft.bkslab.org "cd path/to/dir/you/want ; tar czf - diryouwant1 diryouwant2 " > where/it/goes/locally/file.tar.gz
 
This will compress the data, copy it, and keep the data as a compressed file.
 
 
Another (better) way to copy files is by using rsync and screen.  I am going to use a scenario, say I am going to copy my home to another server.
 
On my desktop:
 
  screen -dR my_home
 
Note that my_home could be anything, it's just the name of the screen.
Then to copy my files:
 
  rsync -arv /home/jill/* someServer:/home/jill/
 
Then to detach from the screen:
 
  Hold ctrl+A, let go and then type d
 
You should now be detached from the screen. 
 
To see a list of your screens type:


  screen -ls


ssh tbalius@sgehead.uoft.bkslab.org "cd path/to/dir/you/want ; tar czf - diryouwant1 diryouwant2 " | tar xzf - -C where/it/goes/locally
To reattach to my screen:


  screen -r my_home




Clear?


[[Category:Internal]]
[[Category:Internal]]

Latest revision as of 19:23, 14 September 2016

One way to copy files to and from a machine is as follows:

To copy from the machine you are on

tar czf - dir1 dir2 dir3 | ssh tbalius@sgehead.bkslab.org "tar xzf - -C path/for/new/files "

To copy from a remote machine to the machine you are on

ssh tbalius@sgehead.uoft.bkslab.org "cd path/to/dir/you/want ; tar czf - diryouwant1 diryouwant2 " | tar xzf - -C where/it/goes/locally

This has advantages that it does not copy symbolic links. It also compresses the data while copying

Clear?

ssh tbalius@sgehead.uoft.bkslab.org "cd path/to/dir/you/want ; tar czf - diryouwant1 diryouwant2 " > where/it/goes/locally/file.tar.gz

This will compress the data, copy it, and keep the data as a compressed file.


Another (better) way to copy files is by using rsync and screen. I am going to use a scenario, say I am going to copy my home to another server.

On my desktop:

 screen -dR my_home

Note that my_home could be anything, it's just the name of the screen. Then to copy my files:

 rsync -arv /home/jill/* someServer:/home/jill/

Then to detach from the screen:

 Hold ctrl+A, let go and then type d

You should now be detached from the screen.

To see a list of your screens type:

 screen -ls

To reattach to my screen:

 screen -r my_home