rcp stands for "remote file copy". This command is used to copy files between computers. The rcp command has two formats. The first format is used for file-to-file copying; the second format is used for copying a file or directory into another directory.
1. Command format:
rcp [parameter] [source file] [object file]
2. Command function:
The rcp command is used to copy files or directories remotely. If more than two files or directories are specified at the same time, and the final destination is an existing directory, it will copy all the previously specified files or directories to in this directory.
3. Command parameters:
the meaning of each option:
-r recursively copy all the contents in the source directory to the destination directory. To use this option, the destination must be a directory.
-p Tries to preserve the modification time and mode of the source file, ignoring the umask.
-k Requests rcp to obtain Kerberos permissions for remote hosts within the specified zone instead of obtaining Kerberos permissions for remote hosts within the remote host zone determined by krb_relmofhostCD.
-x Turn on DES encryption for all data transmitted. This affects response time and CPU utilization, but improves security. If the path specified in the filename is not a full pathname, then the path is interpreted relative to the home directory of the user with the same name on the remote machine. If no remote username is given, the current username is used. If the path on the remote machine contains special shell characters, it needs to be enclosed in backslashes (\\), double quotes ("), or single quotes (') so that all shell metacharacters can be interpreted remotely. Yes, rcp does not prompt for a password, it executes the copy through the rsh command.#p#page header#e#
directory Each file or directory argument can be either a remote filename or a local filename. Remote file names have the form: rname@rhost:path, where rname is the remote user name, rhost is the remote computer name, and path is the path to this file.
4. Use Case:
To use rcp, the following is required:
If there is an /etc/hosts file on the system, the system administrator should ensure that the file contains entries for the remote hosts with which to communicate.
There is a line 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 on the remote system's host directory, which contains the name of the local system and the local login.
For example, the entry in the remote system's .rhosts file might be:
webserver1 root
#p#page title #e#
where webserver1 is the name of the local system and root is the local login name. This allows root on webserver1 to copy files to and from the remote system that contains the .rhosts file.
Configuration process:
Only valid for root user
1. Create a .rhosts file in the root directory of both parties, and add the hostnames of both parties. Before that, add the IP and hostname of the other party to the /etc/hosts file of both parties
2. Start the rsh service, redhat is not started by default.
Method: execute the ntsysv command, select it with the space bar before the rsh option, and confirm to exit. Then execute:
service xinetd restart.
3. Go to the /etc/pam.d/ directory and comment out the line "auth required /lib/security/pam_securetty.so" in the rsh file
with "#". (Only comment out this line, you can log in as root user)
Command usage:
Copy files to remote system
To local system to the remote system, use the following command:
rcplocal_fileremote_hostname:remote_fileEnter
, you need to provide a relative path (starting from the current directory) or an absolute pathname (starting with /) in addition to the local file name.
You only need to specify the full (absolute) path to the remote_file on remote_hostname if you want to put it in another directory (other than the remote home directory). #p#Pagination title#e#
Use example 1: Copy test1 in 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 Under the subdirectory test3, the name is still test1. If only the remote hostname is provided, rcp will copy test1 to the remote home directory, still named test1.
You can also include filenames in the destination directory. For example, copy the file to a system named webserver1:
rcp test1 webserver1:/home/root/test3
In this case, copy #p#pageheader#e#test1 to the remote directory root and name it test3.
Example 2: Copy files from a remote system: To copy a file in the remote system to a local directory
Command :
rcp remote_hostname:remote_file local_fileEnter
Example: 3: Copy test2 in the remote system webserver1 to the current directory:
Command:
rcp webserver1 :/home/root/test2 .Enter
Description:
The dot (.) is a shorthand for "current directory". In this case, test2 in the remote directory is copied to the current directory, still named test2. #p#Pagination Title#e#
If you wish to copy the file with a new name, provide the destination filename.
If you want to copy test2 to another directory on your local system, use the following absolute or relative pathname:
rcp webserver1:/home/root/test2 otherdir/ Enter
Or, if you want to copy the file to another directory with a different filename:
rcp webserver1:/home/root/test2 otherdir/otherfile Enter
Use Case 4: Copying a Directory to a Remote System: To copy a local directory and its 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
Description:
If there is no local_dir in the current directory, in addition to the local directory name, a relative pathname (starting from the current directory) or an absolute pathname (starting from the / top-level directory) needs to be provided. Also, if there is no remote_dir under the home directory, the remote_dir will require a relative path (starting with the home directory) or an absolute path (starting with /). #p#Pagination title#e#
Use example 5:
To completely copy a subdirectory named work to a directory named products under the home directory on the remote computer of webserver1, type the following:
rcp –r work webserver1:/home /root/products Enter
This command creates a directory named work with its entire 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, a relative or absolute path to the directory must be provided, such as /home/root/work.
Use Example 6: Copying a directory from a remote system:
To copy a remote directory and all its files and subdirectories to a local directory, use the rcp with the -r (recursive) option in the following syntax.
Order:
rcp –r remote_hostname:remote_dir local_dir Enter
To copy a remote directory named work to the current directory, type the following:
rcp –r webserver1:/home/root/work .Enter#p#page title#e#
dot (.) Represents the current directory. The work directory will be created under this directory.
Reprinted in: http://www.itxuexiwang.com/a/liunxjishu/2016/0303/208.html?1457083852
A linux command per day (59): rcp command
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=326903684&siteId=291194637
Recommended
Ranking