Linux Command: rcp command, linux Command rcp

Source: Internet
Author: User

Linux Command: rcp command, linux Command rcp

Rcp stands for "remote file copy" (remote file copy ). This command is used to copy files between computers. The rcp command has two formats. The first format is used to copy files to files. 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:

The rcp command is used to remotely copy files or directories. For example, if you specify more than two files or directories at the same time, and the last destination is an existing Directory, then it copies all the previously specified files or directories to this directory.

3.Command parameters:

Meaning of each option:

-R Recursively copies all the content in the source directory to the target directory. To use this option, the object must be a directory.

-P tries to retain the modification time and mode of the source file, ignoring umask.

-K requests rcp to obtain Kerberos permission for the remote host in the specified region, instead of obtaining Kerberos permission for the remote host in the remote host region determined by krb_relmofhost (3.

-X enables DES encryption for all transmitted data. This affects response time and CPU utilization, but improves security. If the path specified in the file name is not the complete path name, the path is interpreted as the Home Directory of the user with the same name on the remote machine. If no remote user name is provided, the current user name is used. If the path on the remote machine contains special shell characters, it must be enclosed by a backslash (\), double quotation marks ("), or single quotation marks, allow remote interpretation of all shell metacharacters. It must be noted that the rcp does not prompt for a password. It uses the rsh command to execute the copy operation.

Each file or directory parameter in directory can be either a remote file name or a local file name. The remote file name can be in the following format: rname @ rhost: path. rname indicates the remote user name, rhost indicates the remote computer name, and path indicates the path of the file.

4.Instance used:

To use rcp, you must meet the following requirements:

If the/etc/hosts file exists in the system, the system administrator should ensure that the file contains items for the remote host to communicate.

The/etc/hosts file contains a line of text, which 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 name of the local system and the local login name.

For example, the items in the. rhosts file of the remote system may be:

Webserver1 root

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

Configuration process:

Effective only for root users

1. Create the. rhosts file under the root directory of both root users, and add the hostnames of both parties. Prior to this, add the IP address and hostname of the other party to the/etc/hosts file of both parties.

2. Start the rsh service. redhat does not start by default.

Method: run the ntsysv command, select it with the Space key before the rsh option, and then exit. Then execute:

Service xinetd restart.

3. In the/etc/pam. d/directory, set auth required/lib/security/pam_securetty.so In the rsh File

Comment out a line. (You can log on as the root user only after you comment out this line)

Command usage:

Copy files to a remote system

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

Rcplocal_fileremote_hostname: remote_fileEnter

Note: If the current directory does not contain local_file, you must provide a relative path (starting from the current directory) or an absolute path (starting from/) in addition to the local file name ).

Only when you want to put the remote_file on remote_hostname to another directory (except the remote main directory), you need to specify the complete (absolute) path for it.

Use instance1:Copy test1 in the current directory to a remote system named webserver1.

Command:

Rcp test1 webserver1:/home/root/test3

Note:

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 copies test1 to the remote home directory and the name is still test1.

You can also include the file name in the target directory. For example, copy the file to a system named webserver1:

Rcp test1 webserver1:/home/root/test3

In this case, copy test1 to the remote root directory and name it test3.

Use instance2:Copy files from a remote system:Copy the files in the remote system to the local directory.

Command:

Rcp remote_hostname: remote_file local_fileEnter

Use instance: 3:Change the remote systemWebserver1InTest2Copy to the current directory:

Command:

Rcp webserver1:/home/root/test2. Enter

Note:

Point (.) is a short form of "Current directory. In this case, test2 in the remote directory is copied to the current directory and the name is still test2.

If you want to copy a file with a new name, provide the target file name.

If you want to copy test2 to another directory in the local system, use the following absolute or relative path name:

Rcp webserver1:/home/root/test2 otherdir/Enter

Alternatively, if you want to copy an object to another directory with another file name:

Rcp webserver1:/home/root/test2 otherdir/otherfile Enter

Use instance4:Copy directory to remote system:To copy local directories and their files and subdirectories to a remote system, use both the rcp and-r (recursive) options.

Command:

Rcp-r local_dir remote_hostname: remote_dir Enter

Note:

If the current directory does not have local_dir, you must provide a relative path name (starting from the current directory) or an absolute path name (starting from/top-level directory) in addition to the local directory name ). In addition, if there is no remote_dir in the main directory, remote_dir requires a relative path (starting from the main directory) or an absolute path (starting from ).

Use instance 5:

To completely copy the subdirectory named work to the products directory in the home directory of the webserver1 remote computer, type the following:

Rcp-r work webserver1:/home/root/products Enter

This command creates a directory named work and all its contents under webserver1:/home/root/products (assuming/home/root/products already exists in webserver1 ).

This example assumes that the user is in the local directory containing work. Otherwise, the relative or absolute path of the Directory, such as/home/root/work, must be provided.

Use instance6:Copy directory from remote system:

To copy the remote directory and all its files and subdirectories to the 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

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

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.