What Is the rcp Command?

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

The rcp command (which stands for remote copy program) copies files to or from a remote computer or between two remote computers. The command 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.

rcp Command in Ubuntu Terminal

The rcp Command and the .rhosts File

To use the rcp command, both computers need an .rhosts file in the user's home directory that contains the names of 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 commands copy 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: Creates a log file that shows which files were copied from the computer. When copying to and from remote computers that don't involve the local computer, only the first transfer is logged.
  • /USER: Specifies the remote computer's user account. This is only used when the remote host's file does not include your username or hostname.
  • /PASSWORD: Identifies the password needed to log in to the remote account. It's used with /USER.
  • -r: Copies 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

Copy 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

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

rcp -r documents zeus.univ.edu:backups 

Copy 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