"Go" one Linux command per day: rcp command

Source: Internet
Author: User
Tags file copy

Original URL: http://www.cnblogs.com/peida/archive/2013/03/14/2958685.html

RCP stands for "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 [parameters] [source file] [target file]

2. Command function:

The RCP command copies files or directories at the remote end, such as specifying more than two files or directories at the same time, and the final destination is a directory that already exists, it will copy all previously specified files or directories to that 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 turns on DES encryption for all transmitted data. 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 examples:

To use RCP, the following conditions are required:

If the system has a/etc/hosts file, the system administrator should ensure that the file contains the entries for the remote host with which to communicate.

There is a line of text in the/etc/hosts file that contains the following information for each remote system:

Internet_address Official_name Alias

For example:

9.186.10.*** Webserver1.com.58.webserver

. rhosts file

The. 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, an entry in a. rhosts file for a remote system might be:

WebServer1 Root

Where WebServer1 is the name of the local system and root is the local login name. In this way, root on the webserver1 can copy files back and forth in the remote system that contains the. rhosts file.

Configuration process:

Valid only for the root user

1. Create the. rhosts file under the root directory of both parties and add the hostname of both sides. Before this, you should add the IP and hostname of each other in the/etc/hosts file of both parties.

2. Starting 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 can be.

3. To the/etc/pam.d/directory, put the auth in the rsh file required/lib/security/pam_securetty.so

A line is commented out with "#". (only comment out this line in order to log in with the root user)

command to use:

Copying files to a remote system

To copy files from the local system to the remote system, use the following command:

Rcplocal_fileremote_hostname:remote_fileenter

Note that 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 (from/To), in addition to the local file name.

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 a remote system named WebServer1

Command:

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

Use Example: 3: Copy the test2 from the remote system WebServer1 to the current directory:

Command:

rcp webserver1:/home/root/test2. Enter

Description

The dot (.) 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 names:

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 the RCP and-R (recursive) options.

Command:

Rcp–r Local_dir Remote_hostname:remote_dir Enter

Description

If there is no local_dir in the current directory, you will need to provide a relative pathname (starting from the current directory) or an absolute pathname (beginning with the/top-level directory) In addition to the local directory name. Also, if there is no remote_dir in the home directory, then Remote_dir will need a relative path (autonomous directory start) or an absolute path (from/to start).

Use Example 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 work Webserver1:/home/root/products Enter

This command creates a directory named work under Webserver1:/home/root/products and all its contents (assuming that/home/root/products already exists 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 the RCP and-R (Recursive) options in the following syntax.

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. Enter

The point (.) indicates the current directory. The work directory will be created under this directory.

"Go" one Linux command per day: rcp command

Related Article

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.