Open In App

rcp Command in Linux with examples

There comes a time while using LINUX when there is a need to copy some information stored in a file to another computer. This can be done simply using rcp command line utility . Obviously there exists some other methods to complete the above mentioned task which are more secure (like scp or rsync) but this command lets you do this in the simple way and a LINUX beginner can use this command to copy files from one computer to another computer. 

Here’s the syntax of rcp command: 

// syntax of rcp command

rcp [-p] [-r] file name ... directory


Using rcp command

To simply use the rcp command, just provide the source and destination to rcp command with a colon used to separate the host and the data. 

/* using rcp command
to send a file from local
host to remote host */

rcp /mydirectory/kt.txt kartik:one/kt.txt

/* the example
above is to send a file
not to receive a file
from remote host */

What actually happening in the above example is the file named kt.txt whose path is given as /mydirectory/kt.txt is getting transferred from this local path (/mydirectory) that is you can say from a local host to the remote system named kartik and the file on that system will be placed in the directory one(as path one/kt.txt is given). 


Options for rcp command



Examples of using rcp command


/*using rcp command
to receive a file from
a remote host */

rcp kartik:one/kt.txt .

/*the difference in the 
syntax of receiving 
is just of not using
the source path before
'kartik' i.e the name of
remote system */
//using rcp with -p option

rcp -p kartik:one/kt.txt
/*using -r option
with rcp */

rcp -r localdir kartik: 
/*using rcp to copy 
two files from local
host to remote host */

rcp kt.txt pt.txt kartik:/var/docs
Article Tags :