linux常用命令:scp 命令

it2026-04-01  11

  scp(secure copy)用于进行远程文件拷贝。

 

1.命令格式:

  scp [参数] [源文件] [目标文件]   

2.命令功能:

  scp在主机间复制文件,他使用 ssh(1)作为数据传输,而且用同样认证和安全性。两个远程登录的服务器间的文件复制是允许的。

3.命令参数:

      1) -r     递归的复制整个文件夹

      2) -p    保留文件的最后修改时间,最后访问时间和权限模式;

 

4.使用实例:

1)root@Unbuntu:/home/sunjimeng/桌面# rcp sunmeng@CentOS:/home/sunmeng/rcptext ./   将远程文件复制到本地

root@Unbuntu:/home/sunjimeng/桌面# ll 总用量 8 drwxr-xr-x 2 sunjimeng sunjimeng 4096 6月 30 08:42 ./ drwxr-xr-x 20 sunjimeng sunjimeng 4096 6月 29 08:27 ../ root@Unbuntu:/home/sunjimeng/桌面# rcp sunmeng@CentOS:/home/sunmeng/rcptext ./ root@Unbuntu:/home/sunjimeng/桌面# ll 总用量 8 drwxr-xr-x 2 sunjimeng sunjimeng 4096 6月 30 08:56 ./ drwxr-xr-x 20 sunjimeng sunjimeng 4096 6月 29 08:27 ../ -rw-r--r-- 1 root root 0 6月 30 08:56 rcptext 

2)root@Unbuntu:/home/sunjimeng/桌面# rcp -r sunmeng@CentOS:/home/sunmeng/Documents ./  复制远程文件到本地

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 总用量 12 drwxr-xr-x 3 sunjimeng sunjimeng 4096 6月 30 08:59 ./ drwxr-xr-x 20 sunjimeng sunjimeng 4096 6月 29 08:27 ../ drwxr-xr-x 2 root root 4096 6月 30 08:59 Documents/ -rw-r--r-- 1 root root 0 6月 30 08:56 rcptext

3)将远程文件复制到本地

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 Unbuntu:root@Unbuntu:/home/sunjimeng/桌面# ll 总用量 8 drwxr-xr-x 2 sunjimeng sunjimeng 4096 6月 30 09:00 ./ drwxr-xr-x 20 sunjimeng sunjimeng 4096 6月 29 08:27 ../ root@Unbuntu:/home/sunjimeng/桌面# touch Unbuntu.txt root@Unbuntu:/home/sunjimeng/桌面# 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

 4)[root@localhost Documents]# rcp -p text2.txt root@Unbuntu:/home/sunjimeng/桌面    复制文件时保留原文件的属性

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 [root@localhost Documents]# rcp text1.txt root@Unbuntu:/home/sunjimeng/桌面 [root@localhost Documents]# rcp -p text2.txt root@Unbuntu:/home/sunjimeng/桌面 Unbuntu: root@Unbuntu:/home/sunjimeng/桌面# ll 总用量 16 drwxr-xr-x 2 sunjimeng sunjimeng 4096 6月 30 09:20 ./ drwxr-xr-x 20 sunjimeng sunjimeng 4096 6月 30 09:18 ../ -rw-r--r-- 1 root root 38 6月 30 09:19 text1.txt -rw-r--r-- 1 root root 46 6月 27 22:19 text2.txt

 

5.其他:

    rcp余scp的区别:

    rcp通过rsh方式远端复制文件或目录;scp通过ssh方式远端复制文件或目录。

    rcp是一种不安全的的传输文件的方式,scp则比较安全,但有可能scp命令执行时需要用户输入密码和口令。

    linux下不同服务器间数据传输命令和工具:rcp,scp,rsync,ftp,sftp,lftp,wget,curl。(http://blog.csdn.net/emili/article/details/6858818)

转载于:https://www.cnblogs.com/shujuxiong/p/9013759.html

最新回复(0)