System Administration Guide: Resource Management and Network Services

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

Here are several examples of using rcp to copy files to and from local and remote systems.

Using rcp to Copy a Remote File to a Local System

In this example, rcp is used to copy 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 .

In this instance, the rcp operation is performed without a remote login. Here, the “.” symbol at the end of the command line refers to the local system, not the remote system.

The target directory is the also local user's home directory, so it can also be specified with the “~” symbol.


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

Using rlogin and rcp to Copy a Remote File to a Local System

In this example, the rcp operation is run after the rlogin command is executed to copy a file from a remote to a local system. Although the flow of the operation is the same as that of the previous example, the paths change to allow for the remote login:


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

Using the “.” symbol at the end of the command line would be inappropriate in this instance. Because of the remote login, the symbol would simply refer 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 the login is to a remote system.

Using rcp to Copy a Local File to a Remote System

In this example, rcp is used to copy 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

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

In this instance, the rcp operation from the previous example 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

Using rlogin and rcp to Copy a Local File to a Remote System

In this example, the rcp operation is run after the rlogin command is executed to copy a local file to a remote directory. Although the flow of the operation is the same as that of the previous example, the paths change to allow for the remote login.


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

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