Linux common commands: scp command

  scp (secure copy) is used for remote file copying.

 

1. Command format:

  scp [parameters] [source file] [destination file]   

2. Command function:

  scp copies files between hosts, it uses ssh(1) for data transfer, and uses the same authentication and security. File copying between two remote login servers is allowed.

3. Command parameters:

      1) -r Copy the entire folder recursively

      2) -p preserves the last modification time of the file, the last access time and the permission mode;

 

4. Example of use:

1) root@Unbuntu:/home/sunjimeng/desktop# rcp sunmeng@CentOS:/home/sunmeng/rcptext ./ Copy remote files to local

copy code
root@Unbuntu:/home/sunjimeng/桌面# ll
Dose 8 
drwxr-xr-x   2 sunjimeng sunjimeng 4096 June 30 08:42 ./ drwxr-xr-x 20 sunjimeng sunjimeng 4096 June 29 08 : 27 ../ root @ Unbuntu: /home/sunjimeng/ sunmeng @ CentOS: / home / sunmeng / rcptext ./ root @ Unbuntu: / home / sunjimeng /桌 葉 # ll 总 DT 8 drwxr-xr-x 2 sunjimeng sunjimeng 4096 June 30 08:56 ./ drwxr-xr-x 20 sunjimeng sunjimeng 4096 June 29 08: 27 ../ -rw-r--r-- 1 root root 0 June 30 08:56 rcptext 
copy code

2)root@Unbuntu:/home/sunjimeng/desktop# rcp -r sunmeng@CentOS:/home/sunmeng/Documents ./ Copy remote files to local

copy code
root@Unbuntu:/home/sunjimeng/桌面# rcp sunmeng@CentOS:/home/sunmeng/Documents ./
rcp: /home/sunmeng/Documents: not a plain file
root@Unbuntu:/home/sunjimeng/桌面# rcp -r sunmeng@CentOS:/home/sunmeng/Documents ./
root@Unbuntu:/home/sunjimeng/桌面# ll Total usage 12 drwxr-xr-x 3 sunjimeng sunjimeng 4096 Jun 30 08:59 ./ drwxr-xr-x 20 sunjimeng sunjimeng 4096 Jun 29 08 : 27 ../ drwxr-xr-x 2 root root 4096 Jun 30 08:59 Documents/ -rw-r--r-- 1 root root 0 Jun 30 08:56 rcptext
copy code

3) Copy the remote file to the local

copy code
CentOS:
[root@localhost Documents]# ll Total dosage 8 -rw-r--r--. 1 root root 38 Jun 27 07: 19 text1.txt -rw-r--r--. 1 root root 46 Jun 27 07: 19 text2.txt Unbuntu:
root@ Unbuntu: /home/sunjimeng/ desktop# ll total usage 8 drwxr-xr-x 2 sunjimeng sunjimeng 4096 Jun 30 09:00 ./ drwxr-xr-x 20 sunjimeng sunjimeng 4096 Jun 29 08: 27 ../ root@ Unbuntu:/home/sunjimeng/ Desktop# touch Unbuntu.txt root@Unbuntu:/home/sunjimeng/Desktop# rcp ./Unbuntu.txt sunmeng@CentOS:/home/sunmeng/Documents/ CentOS:
[root@localhost Documents]# ll 总用量 8 -rw-r--r--. 1 root root 38 6月 27 07:19 text1.txt -rw-r--r--. 1 root root 46 6月 27 07:19 text2.txt -rw-r--r-- 1 sunmeng sunmeng 0 6月 29 18:05 Unbuntu.txt
copy code

 4)[root@localhost Documents]# rcp -p text2.txt root@Unbuntu:/home/sunjimeng/Desktop retain the attributes of the original file when copying files

copy code
CentOS:
[root@localhost Documents]# ll
Total dosage 8
-rw-r--r--. 1 root root 38 Jun 27 07:19 text1.txt -rw-r--r--. 1 root root 46 Jun 27 07:19 text2.txt [root@localhost Documents]# rcp text1.txt root@Unbuntu:/home/sunjimeng/ Desktop [root@localhost Documents]# rcp -p text2.txt root@Unbuntu:/home/sunjimeng/ Desktop Unbuntu: root@Unbuntu:/home/sunjimeng / desktop# ll total usage 16 drwxr-xr-x 2 sunjimeng sunjimeng 4096 Jun 30 09:20 ./ drwxr-xr-x 20 sunjimeng sunjimeng 4096 Jun 30 09 : 18 ../ -rw-r--r- - 1 root root 386月 30 09:19 text1.txt -rw-r--r-- 1 root root 46 6月 27 22:19 text2.txt
copy code

 

5. Others:

    The difference between rcp and scp:

    rcp remotely copies files or directories through rsh; scp remotely copies files or directories through ssh.

    rcp is an unsafe way to transfer files, while scp is more secure, but it is possible that the user needs to enter a password and password when the scp command is executed.

    Commands and tools for data transfer between different servers under Linux: rcp, scp, rsync, ftp, sftp, lftp, wget, curl. (http://blog.csdn.net/emili/article/details/6858818)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326153637&siteId=291194637