System Administration Guide

Remote Copying With rcp

The rcp command copies files or directories between a local and a remote system or between two remote systems. You can use it from a remote system (after logging in with the rlogin command) or from the local system (without logging in to a remote system).

With rcp, you can perform the following remote copy operations:

If you have the automounter running, you can perform these remote operations with the cp command. However, the range of cp is constrained to the virtual file system created by the automounter and to operations relative to a user's home directory and, since rcp performs the same operations without these constraints, this section will describe only the rcp versions of these tasks.

Security Considerations for Copy Operations

To copy files or directories between systems, you must have permission to log in and copy files.


Caution - Caution -

Both the cp and rcp commands can overwrite files without warning. Make sure file names are correct before executing the command.


Specifying Source and Target

With the rcp command in the C-shell, you can specify source (the file or directory you want to copy) and target (the location into which you will copy the file or directory) with either absolute or abbreviated pathnames.

Graphic

Absolute pathnames identify files or directories mounted on a particular system. In the example above, the first absolute pathname identifies a file (MyFile.txt) on the mars system. Abbreviated pathnames identify files or directories relative to a user's home directory, wherever that may reside. In the first example above, the abbreviated pathname identifies the same file, MyFile.txt, but uses "~" symbol to indicate the jones home directory. In effect . . .

~ = mars:/home/jones

The examples on the second line, above, demonstrate the user of absolute and abbreviated pathnames after a remote login. There is no difference for the abbreviated pathname, but because the remote login operation mounted the jones home directory onto the local system (parallel to the local user's home directory), the absolute pathname no longer requires the system name mars. For more information about how a remote login operation mounts another user's home directory, see "What Happens After You Log In Remotely".

Table 46-3 provides a representative sample of absolute and abbreviated pathnames recognized by the C shell. It uses the following terminology:

Table 46-3 Allowed Syntaxes for Directory and File Names

Logged in to 

Syntax 

Description 

Local system  

.

The local working directory 

 

path/filename

The path and filename in the local working directory

 

The current user's home directory 

 

~/path/filename

The path and filename beneath the current user's home directory

 

~user

The home directory of user

 

~user/path/filename

The path and filename beneath the home directory of user

 

remote-system:path/filename

The path and filename in the remote working directory

Remote system 

.

The remote working directory 

 

filename

The filename in the remote working directory

 

path/filename

The path and filename in the remote working directory

 

The current user's home directory 

 

~/path/filename

The path and filename in the current user's home directory

 

~user

The home directory of user

 

~user/path/filename

The path and filename beneath the home directory of user

 

local-system:path/filename

The path and filename in the local working directory

How to Copy Files Between a Local and a Remote System (rcp)

  1. Be sure you have permission to copy.

    You should at least have read permission on the source system and write permission on the target system.

  2. Determine the location of the source and target.

    If you don't know the path of the source or target, you can first log into the remote system with the rlogin command, as described in "How to Log In to a Remote System (rlogin) ". Then, navigate through the remote system until you find the location. You can then perform the next step without logging out.

  3. Copy the file or directory.


    $ rcp [-r]source-file|directory   target-file|directory
    

    rcp

    (No options) Copies a single file from the source to the target.  

    -r

    Copies a directory from the source to the target. 

    This syntax applies whether you are logged in to the remote system or in to the local system. Only the pathname of the file or directory changes, as described in Table 46-3, and as illustrated in the examples below.

    You can use the "~" and "." characters to specify the path portions of the local file or directory names. Note, however, that "~" applies to the current user, not the remote system, and that "." applies to system you are logged into. For explanations of these symbols, see Table 46-3.

Examples--Copying Files Between a Local and a Remote System (rcp)

Here are a few examples. In the first two, the source is remote; in the last two, the source is local.

In this example, rcp copies the file letter.doc from the /home/jones directory of the remote system pluto to the working directory (/home/smith) on the local system, earth:


earth(/home/smith): rcp pluto:/home/jones/letter.doc .
Graphic

Since the rcp operation is performed without a remote login, the "." symbol applies to the local system, not the remote system.

The working directory happens to be the local user's home directory, so it could have been specified with the "~" symbol as well:


earth(home/smith): rcp pluto:/home/jones/letter.doc ~

In the following example, rcp is used --while logged in to the remote system-- to perform the same operation. Although the flow of the operation is the same, the paths change to take into account the remote login:


earth(/home/smith): rlogin pluto
.
.
. 
pluto(/home/jones): rcp letter.doc ~
Graphic

Use of the "." symbol would be inappropriate in this instance because of the remote login; it would simply apply to the remote system, essentially directing rcp to create a duplicate file. The "~" symbol, however, refers to the current user's home directory, even when logged in to a remote system.

In the following example, rcp copies the file notice.doc from the home directory (/home/smith) of the local system earth to the /home/jones directory of the remote system, pluto:


earth(/home/smith): rcp notice.doc pluto:/home/jones
Graphic

Because no remote filename is provided, the file notice.doc is copied into the /home/jones directory with the same name.

In this example, the operation is repeated, but rcp is entered from a different working directory on the local system (/tmp). Note the use of the "~" symbol to refer to the current user's home directory:


earth(/tmp): rcp ~/notice.doc pluto:/home/jones

In this example, rcp is used --while logged in to the remote system-- to perform the same operation as in the previous example. Although the flow of the operation is the same, the paths change the take into account the remote login:


earth(/home/smith): rlogin pluto
.
.
. 
pluto(/home/jones): rcp ~/notice.doc .
Graphic

In this instance, the "~" symbol can be used to denote the current user's home directory, even though it is on the local system. The "." symbol refers to the working directory on the remote system because the user is logged in to the remote system. Here is an alternative syntax that performs the same operation:


pluto(/home/jones): rcp earth:/home/smith/notice.doc /home/jones