What Is the rcp Command?

What the rcp Linux command is for and how to use it

Man's hand holding computer mouse
Erik Kalibayev/Moment Open/Getty Images

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

rcp is 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 be able to use the rcp command, both computers need a ".rhosts" file in the user's home directory, which would contain the names of all the computers that are allowed to access this computer, along with the user name.

Here's an example of an .rhosts file:

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

Tip: The ftp or scp command can be used to copy files between computers if no .rhosts file is set up.

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 hosts file does not already include your user name or host name.
  • /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.

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 a 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 means "this" directory. That is, the directory from which the command was executed. You could specify any other directory instead.

Copy a Whole Folder

You can copy a complete directory by adding a "-r" after "rcp":

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

Copy From/to the Local Machine

Copies "document1" from the local machine to the user's home directory on the computer with URL zeus.univ.edu, assuming that the user names 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 user names are the same on both systems.

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

Copies the directory "documents", including all subdirectories, from the remote machine to the directory "study" on the local machine.