Remote Copy: rcp

next up previous contents index
Next: Network File System Up: Unix to Unix Previous: Commands from Remote

Remote Copy: rcp

In the preceding examples it would have been more convenient to already have the files on the remote machine and then copy them back to our local machine when done working. In this way we avoid both worrying about a number of things at once and issuing a long and error-prone command. This is possible by using the remote copy command rcp. In general, the rcp command works like the standard copy command cp, but with the additional features of being able to specify a remote machine as well as your user ID on the remote machine. Like the rsh command, rcp goes to your home directory on the remote machine. To copy a file to or from another directory, you must specify the path name for the file relative to your home directory. For example, to copy your .cshrc file from machine to machine:

% rcp local.file remhost:rfile   	Copy local file to remote one.   
% rcp .cshrc remhost:   	Copy local .cshrc file to machine remhost.   
% rcp remhost:.cshrc .   	Copy remote .chsrc file to local machine.   

When no file name is specified for the second machine, the file will have the same name as it had on the first machine.

In our next example, bohr copies some input files on the local machine to the remote machine phy1 and then runs his program on the remote machine. When the program is completed, he copies the output files back to his local machine:

% ls    inputs   	User bohr has two input files.   
% rcp inputs phy1:proj/runs   	He copies both   
   	 to remote machine's directory runs.   
% rsh phy1 "cd proj/runs;  /u/bohr/proj/bin/calcL"   	Run remote job with input files.   
   	After the job has completed,   
% rsh phy1 ls -l proj/runs   	 check for the output files.   
-rwxr-- 1 bohr    10908 Mar 10   	    
-rwxr-- 1 bohr    40696 Mar 10   	    
09:53 inputs   	   
-rwxr-- 1 bohr  2158225 Mar 10   	    
22:34 data.output   	   
% rcp phy1:proj/runs/data.output .   	Copy output file to local machine.   

As with the other remote commands, you can also specify your user ID on the remote machine if it is different from your user ID on the local machine. This is done by using the same notation as for the mail or finger commands. Here bohr copies a file to phy2 where his user ID is niels:

% rcp calcL.c niels@phy2:myprog   	   Remote copy with 2 names.   

There are two options that make rcp very handy, namely, -r to indicate recursive copy, and -p to preserve modification dates and file permissions. The rcp -r command copies a directory and all of the files and subdirectories below it. The rcp -p command preserves modification dates and file permissions; this helps make the remote files look just like they do at home as well as being useful for utilities such as make. For example:

% rcp -rp src remhost:newproject   	Recursive, permissive copy of src.   

copies the complete directory src to the machine remhost. In the process, it creates a new directory src under the directory newproject on the remote machine. The -p part of the option preserves the modification times of all of the files.

next up previous contents index
Next: Network File System Up: Unix to Unix Previous: Commands from Remote