How to Copy Files and Directories To and From Another System with 'rcp' Command

Copying Files or Directories To and From Another System

You can use the rcp command to copy files or directories from one host to another. To copy subdirectories and their contents, you can use the ‘rcp -r’ command. The syntax for the rcp command is:

$ rcp source_file hostname:destination_file
or

$ rcp hostname:source_file destination_file

or
$ rcp hostname:source_file hostname:destination_file

Copying Files From a Local Directory To a Remote Host

You can use the rcp command to copy files from a local directory to a remote host. The rcp command checks the ~/.rhosts file to determine if you have the necessary access permissions. The following example shows you how to copy the dante file from the local directory to the /tmp directory on a system called host2.

$ rcp dante host2:/tmp

Copying Files From a Remote Host To a Local Directory

You can use the rcp command to copy files from a remote host to the local /tmp directory. The /tmp directory is used because it has read, write, and execute permissions for each category of user. The following example shows you how to copy the dante file from a remote host called host2 to the local /tmp directory.

$ rcp host2:/tmp/dante /tmp

Copying Remote Directories

You can use the rcp command with the -r option to copy directories to and from another system. If your current working directory contains the file or directory that you want to copy, use the file or directory name. You do not need to use the absolute path name. The following example shows you how to copy the perm directory in the local home directory to the /tmp directory on the host system called host2.

$ rcp -r ~/perm host2:/tmp