Rcp

From LQWiki
Jump to navigation Jump to search

The rcp (remote copy) command is part of the Berkely RPC (Remote Procedure Call) package. (See rsh and rdist for other examples.) It lets you copy a file from one machine to another, almost as easily as copying a file between two directories.

Caveat

Please learn to use scp instead of rcp. scp was written with security in mind, which was never part of rcp's design.

Copying to/from remote machines

The basic form of the rcp command is very simple. Say we have a file called "books" that we've edited on our local machine, and we need to give Greta a copy. The sysadmin values utility over everything else, so Greta's machine is called "greta". We're going to assume we're on a small LAN, so we don't need to worry about a domain name. To copy the file from our home directory on the local machine, to our home directory on Greta's machine, we'd type:

rcp books greta:

Let's say we don't have an account on Greta's machine. We could write it to /tmp:

rcp books greta:/tmp

Now let's go the other way. Greta has been doing some work on the file called "tapes" and we want a copy of that for ourselves:

rcp greta:/home/greta/tapes .

(The "." means "the current directory).

Finally, just to show what the whole thing looks like, we'll assume we're in our home directory, but we want to copy something to a different directory.

rcp greta:/usr/acctng/gl/inventory/tapes /usr/acctng/gl/inventory

If you don't put a "/" in front of the file name (but after the colon), it will assume you're in your home directory. If we had run:

rcp greta:usr/acctng/gl/inventory/tapes /usr/acctng/gl/inventory

it would have tried to go to our home directory, and then the usr/acctng/gl/inventory directory under that. If what you want IS somewhere in your home directory, that's fine. If it's not, be sure to remember to put the "/" right after the colon.