Linux Command Learning Note: rcp command

Source: Internet
Author: User
Tags file copy

RCP stands for "remotefileCopy "(Remote file copy). This command is used to copy files between computers. The RCP command has two forms. The first format is used for file-to-file copies, and the second format is used to copy files or directories to another directory. 1. Command format: rcp [parameter] [source file] [target file]2. Command function: rcp command is used to copy files or directories at the remote location, such as specifying more than two files or directories at the same time, and the final destination is an existing directory, it will copy all the previously specified files or directories into the directory. 3. Command parameters: Each option means:-R recursively copies all the contents of the source directory to the destination directory. To use this option, the destination must be a directory. -P attempts to preserve the modified time and mode of the source file, ignoring umask. -K requests that RCP obtain a Kerberos license for the remote host within the specified zone, rather than obtaining a Kerberos license for the remote host in the remote host zone determined by Krb_relmofhost⑶. -x Open des encryption for all data transferred. This affects response time and CPU utilization, but it can improve security. If the path specified in the file name is not the full pathname, then this path is interpreted as relative to the home directory of the user with the same name on the remote machine. If the remote user name is not given, the current user name is used. If the path on the remote machine contains special shell characters, it needs to be surrounded by a backslash (\ \), double quotation mark ("), or single quotation mark (') so that all shell metacharacters can be interpreted remotely. It is important to note that RCP does not prompt for a password, which executes the copy through the RSH command. Directory each file or directory parameter can be either a remote file name or a local file name. The remote file name has the following form: [E-mail Protected]:path, where rname is the remote user name, Rhost is the remote computer name, path is the pathname of this file. 4. Usage Example: To use RCP, the following conditions are required: If the system has/etc/Hosts file, the system administrator should ensure that the file contains the entries for the remote host with which to communicate. /etc/there is a line of text in the Hosts file that contains the following information for each remote system: Internet_address Official_name alias for example:9.186.Ten. * * * webserver1.com. -The . webserver.rhosts file. rhosts file is located in the home directory of the remote system, which contains the local system name and the local login name. For example, the entry in the. rhosts file for the remote system might be: WebServer1 root where WebServer1 is the name of the local system and root is the local login. In this way, root on the webserver1 can copy files back and forth in the remote system that contains the. rhosts file. Configuration process: Only valid for root user1. Create the. rhosts file under the root directory of both parties and add the hostname of both sides. Before this should be on both sides of the/etc/Hosts file to add each other's IP and hostname2To start the Rsh service, Redhat is not started by default. Method: Use the Execute NTSYSV command, with the SPACEBAR selected before the RSH option, to determine exit. Then execute: Service xinetd restart. 3. To the/etc/pam.d/directory, put the auth in the rsh file required/lib/security/pam_securetty.so a line with "#" comment out. (only comment out this line to use the root login) command: Copy files to the remote system to copy files from the local system to the remote system, use the following command: Rcplocal_fileremote_hostname:remote_fileenter note , if there is no local_file in the current directory, you will need to provide a relative path (starting from the current directory) or an absolute pathname (since the local file name)/start). You need to specify a full (absolute) path only if you want the remote_file on Remote_hostname to be placed under a different directory (except for the Remote home directory). Use instance 1: Copy the test1 under the current directory to the remote system command named WebServer1: rcp test1 webserver1:/home/root/test3 Description: In this case, Test1 is copied to the remote subdirectory test3, and the name is still test1. If only the remote host name is provided, RCP will copy the test1 to the remote home directory, and the name will still be test1. You can also include the file name in the destination directory. For example, copy the file to a system named WebServer1: rcp test1 webserver1:/home/root/Test3 In this case, copy the test1 to the remote directory root and name it test3. Use instance 2: Copy files from a remote system: to copy files from a remote system to a local Directory command: RCP remote_hostname:remote_file local_fileenter usage Example:3: Copy test2 from remote system WebServer1 to the current directory: command: rcp webserver1:/home/root/test2. Enter Description: The point (.) is a shorthand for the current directory. In this case, the test2 in the remote directory is copied to the current directory, and the name is still test2. If you want to copy the file with a new name, provide the destination file name. If you want to copy Test2 to a different directory on your local system, use the following absolute or relative path name: rcp webserver1:/home/root/test2 otherdir/Enter or, if you want to copy the file to a different directory with another file name: rcp webserver1:/home/root/test2 otherdir/Otherfile Enter use instance 4: Copy the directory to the remote system: to copy the local directory and its files and subdirectories to the remote system, use both RCP and-r (Recursive) option. Command: Rcp–r local_dir remote_hostname:remote_dir Enter Description: If there is no local_dir in the current directory, in addition to the local directory name, you also need to provide a relative pathname (starting from the current directory) or an absolute pathname (from /top-level directory start). Also, if there is no remote_dir in the home directory, then Remote_dir will need a relative path (autonomous directory start) or absolute path (from/start). Use instance 5: To completely copy a subdirectory named work to a directory named products in the home directory on the WebServer1 remote computer, type the following: Rcp–r WebServer1:/home/root/Products Enter this command in WebServer1:/home/root/Products under Create a directory named work and all of its contents (assuming/home/root/Products already exist in WebServer1). This example assumes that the user is in a local directory that contains work. Otherwise, you must provide a relative or absolute path to the directory, such as/home/root/Work . Use instance 6: Copy a directory from a remote system: To copy the remote directory and all of its files and subdirectories to a local directory, use RCP in the following syntax and-r (Recursive) option. Command: Rcp–r remote_hostname:remote_dir local_dir Enter to copy the remote directory named work to the current directory, type the following: Rcp–r WebServer1:/home/root/Work . The Enter point (.) indicates the current directory. The work directory will be created under this directory. 

Linux Command Learning Note: rcp command

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.