What Is the rcp Command?

Copy files to and from a remote computer with 'rcp'

Working on a laptop
Manuel Breva Colmeiro / Getty Images

The rcp command (which stands for remote copy program) copies files to or from a remote computer or between two remote computers.

The program is similar to cp, except that the remote computer and possibly the username on the remote computer both need to be prefixed to the file name.

To use the rcp command, both computers need an .rhosts file in the user's home directory that contains the names of all the computers that are allowed to access the computer, along with each authorized username.

Here's an example of an .rhosts file:

zeus.univ.edu jdoe
athena.comp.com mjohnson

The ftp or scp command copies files between computers if no .rhosts file is set up.

The 'rcp' Command Syntax

The proper syntax when using the rcp command is to type rcp followed by the source and then the destination. Use a colon to separate the host and data.

Here are some of the options you can add to the rcp command:

  • /LOG: A log file is created that shows which files were copied from the computer. When copying to and from remote computers that don't involve the local computer at all, only the first transfer is logged.
  • /USER: Specifies the remote computer's user account. It's to be used only when the remote host's file does not already include your username or hostname.
  • /PASSWORD: This is the password needed to log into the remote account. It's used with /USER.
  • -r: Used to copy an entire directory with the rcp command.
  • -p: Allows the copy to maintain the date that the data was modified a well as the file protection mode. It's the same as /PRESERVE.

Several 'rcp' Command Examples

Here are just a few examples of how to use rcp in Linux:

Copy a Single File

The following needs to be entered on the command line to copy a file called customer.txt in the directory /usr/data/ from computer tomsnotebook to the current directory:

rcp tomsnotebook:/usr/data/customers.txt . 

The period at the end of the command stipulates the current active directory. You could specify any other directory instead.

Copy a Whole Folder

Copy a complete directory by adding -r:

rcp -r tomsnotebook:/usr/data .
rcp document1 zeus.univ.edu:document1

Copy From/to the Local Machine

Copy document1 from the local machine to the user's home directory on the computer with URL zeus.univ.edu, assuming that the usernames are the same on both systems:

rcp document1 jdoe@:zeus.univ.edu:document1 

Copies document1 from the local machine to the home directory of user jdoe on the computer with URL zeus.univ.edu:

rcp zeus.univ.edu:document1 document1 

Copies document1 from the remote computer zeus.univ.edu to the local machine with the same name:

rcp -r documents zeus.univ.edu:backups 

Copies the directory documents, including all subdirectories, from the local machine to the directory backups in the user's home directory on the computer with URL zeus.univ.edu, assuming that the usernames are the same on both systems:

rcp -r zeus.univ.edu:backups/documents study