Sunday 29 January 2012

rcp


rcp
rcp is used to copy or send files or directories between two hosts. It can be used an alternative to ftp  and related protocols like sftp, but no password is required to send files unlike ftp.
For rcp to work,  various  prerequisites are required ,which  are same for the  rsh command.(refer rsh)

Assume  your  hostname is  Prod-serv  and IP is 192.158.0.140  and the remote hostname is
Test-serv and IP is 192.158.0.120 .The local user is kumar and remote user is  warren  in all of the examples.

Example 1)
To send a file  from a  local host to remote host.

/home/kumar$ rcp   Audit_document.txt    warren@192.158.0.120:

This sends the local file    Audit_document.txt  to the host  Test-serv  (you can use Test-serv  in place of  the IP address)  and places it in the $HOME directory of  warren.
With the name  Audit_document.txt and owner of the file  as  warren.

Example 2)
To receive   a file from remote host to local  host.
/home/kumar$ rcp    warren@192.158.0.120:global/Meal_pass2.prt   .
This  copies the file  Meal_pass2.prt  in /home/warren/global  directory of  192.158.0.120
to the current directory (/home/kumar  denoted here  by   ‘.’  or dot).

rcp  just like cp changes the modification time(time stamp) of the destination file to the latest time. To retain the same time stamp  use  rcp –p . The  above example can be written as


Example 3)
To copy directories  between hosts  use rcp  with –r option.

/home/kumar$ ls  -ld  localdir
drwxr-xr-x    2  kumar   tools        256  Jul 14  2009  localdir

/home/kumar$rcp   -r  localdir   warren@192.15.0.120:
This copies  the entire directory localdir(its sub directories)  to  $HOME directory of  warren@192.15.0.120.


More examples:
  • To  copy  two files  booked_ticket1.txt  , booked_ticket2.txt   to /var/docs directory of  192.15.0.120
rcp    booked_ticket.txt   booked_ticket2.txt   warren@192.15.0.120: /var/docs
or
rcp  booked_ticket?.txt    warren@192.15.0.120: /var/docs


  • To  copy  the file  ‘pattern-styles.tar.gz’    to    /home/warren/images  directory of  192.15.0.120  as  style1.tar.gz with same  time stamp.
rcp    -p    pattern-styles.tar.gz    warren@192.15.0.120: images/style1.tar.gz

No comments:

Post a Comment