1. 本地拷贝到远程

文件拷贝
[root@m01 ~]# scp -p /etc/hosts root@10.0.0.8:/tmp
root@10.0.0.8’s password:
hosts 100% 215 0.2KB/s 00:00
目录拷贝
[root@m01 ~]# scp -rp /server root@10.0.0.8:/tmp
root@10.0.0.8’s password:
youhua.sh 100% 747 0.7KB/s 00:00

2. 远程拷贝到本地

文件拷贝
[root@m01 ~]# scp -P65533 -p root@10.0.0.8:/etc/hosts /tmp
root@10.0.0.8’s password:
hosts 100% 215 0.2KB/s 00:00
目录拷贝
[root@m01 ~]# scp -P65533 -rp root@10.0.0.8:/selinux /tmp
root@10.0.0.8’s password:
test.jpg 100% 0 0.0KB/s 00:00
[root@m01 ~]# ll /tmp/selinux/
total 0
-rw-r—r— 1 root root 0 Nov 2 06:36 test.jpg
参数详解:
-P (大写P)指定端口
-r 拷贝目录
-p (小写p)保持属性
-l limit 限制速度

scp知识小结:

  1. scp是加密的远程拷贝,而cp仅为本地拷贝
  2. 可以把数据从一台机器推送到另一台机器,也可以从其它服务器把数据拉回到本地
  3. 每次都是全量完整拷贝,因此,效率不高,适合一次拷贝使用,如果需要增量拷贝,用rsync