基于linux下的远程传输

系统中的文件传输:

1,scp指令,传输较慢:

scp file username@ip:/dir          上传

例如:scp file root@172.25.254.121:/root/Desktop

意思就是将本地文件上传到IP为172.25.254.121的主机的桌面上。

下图为将文件file1从一台虚拟机传到另外一台虚拟机。


二三图为将一个虚拟机桌面建立的所有文件传输到另外一台虚拟机。


scp    username@ip:/dir/file  /dir        下载

例如:scp   root@172.25.254.121:/root/Desktop/file  /root/Desktop

表示将IP为172.25.254.121主机桌面的文件下载到本地的桌面上面。

下图为将一台虚拟机里面的/etc/目录通过递归形式-r传递到另外一台虚拟机的/mnt/目录下。


2,rsync命令,传输速度快:

rsync [参数] file username@ip:/dir

rsync -r                 同步目录

-l                       不忽略链接

-p                       不忽略文件权限

-t                       不忽文件时间戳

-g                       不忽文件所有组

-o                       不忽文件所有人

-D                       不忽略设备文件

rsync远程数据同步,比scp命令同步命令快的多。下图可以看出来跳过了很多文件,进而加快了速度。


[root@localhost mnt]# cd /mnt  更改路径

[root@localhost mnt]# ll       查看

total 0

[root@localhost mnt]# touch file{1..5} 建立文件

[root@localhost mnt]# chmod 777 *      赋予满权限

[root@localhost mnt]# ll               查看

total 0

-rwxrwxrwx. 1 root root 0 Apr  6 03:05 file1

-rwxrwxrwx. 1 root root 0 Apr  6 03:05 file2

-rwxrwxrwx. 1 root root 0 Apr  6 03:05 file3

-rwxrwxrwx. 1 root root 0 Apr  6 03:05 file4

-rwxrwxrwx. 1 root root 0 Apr  6 03:05 file5

[root@localhost mnt]# chown student.student *  更改用户和组为student

[root@localhost mnt]# ll

total 0

-rwxrwxrwx. 1 student student 0 Apr  6 03:05 file1

-rwxrwxrwx. 1 student student 0 Apr  6 03:05 file2

-rwxrwxrwx. 1 student student 0 Apr  6 03:05 file3

-rwxrwxrwx. 1 student student 0 Apr  6 03:05 file4

-rwxrwxrwx. 1 student student 0 Apr  6 03:05 file5


[root@localhostmnt]# rsync -r /mnt root@172.25.254.121:/mnt/ 传输到121虚拟机上面但是没有用户组权限时间不对应。

root@172.25.254.121's password:


[root@localhost mnt]# rsync -rp /mnt root@172.25.254.121:/mnt/  同步权限

root@172.25.254.121's password:


[root@localhost mnt]# rsync -rpo /mnt root@172.25.254.121:/mnt/  进而同步用户

root@172.25.254.121's password:


[root@localhost mnt]# rsync -rpog /mnt root@172.25.254.121:/mnt/  进而同步组

root@172.25.254.121's password:


[root@localhost mnt]# rsync -rpogt /mnt root@172.25.254.121:/mnt/  进而同步时间

root@172.25.254.121's password:  


rsync -r /mnt root@172.25.254.121:/mnt/   仅仅复制内容

rsync -r /mnt/ root@172.25.254.121:/mnt/  连同复制本身

同步链接:

[kiosk@foundation21 Desktop]$ ssh root@172.25.254.221 连接server虚拟机

root@172.25.254.221's password:

Last login: Fri Apr  6 03:02:01 2018 from 172.25.254.21

[root@localhost ~]#

[root@localhost ~]# cd /mnt       更改目录

[root@localhost mnt]# ll     

total 0

-rwxrwxrwx. 1 student student  0 Apr  6 03:05 file1

-rwxrwxrwx. 1 student student  0 Apr  6 03:05 file2

-rwxrwxrwx. 1 student student  0 Apr  6 03:05 file3

-rwxrwxrwx. 1 student student  0 Apr  6 03:05 file4

-rwxrwxrwx. 1 student student  0 Apr  6 03:05 file5

lrwxrwxrwx. 1 root    root    10 Apr  6 03:38 westos -> /mnt/file1

[root@localhost mnt]# ln -s /mnt/file1 /mnt/westos 建立快捷方式

[root@localhost mnt]# rsync -r /mnt root@172.25.254.121:/mnt/

root@172.25.254.121's password:

skipping non-regular file "mnt/westos"     同步时跳过快捷方式

[root@localhost mnt]# rsync -rl /mnt root@172.25.254.121:/mnt/ 同步快捷方式

root@172.25.254.121's password:

查看用ll mnt/


同步设备文件:

[root@localhost mnt]# ll /dev/pts/

total 0

crw--w----. 1 root tty  136, 0 Apr  6 03:42 0

crw--w----. 1 root tty  136, 3 Apr  6 02:42 3

c---------. 1 root root   5, 2 Apr  5 21:55 ptmx

[root@localhost mnt]# rsync -r /dev/pts root@172.25.254.121:/mnt/  查看时候                                                                     ll pts/

root@172.25.254.121's password:

skipping non-regular file "pts/0"

skipping non-regular file "pts/3"

skipping non-regular file "pts/ptmx"   直接同步跳过三个设备文件

查看时候用ll /dev/pts

[root@localhost mnt]# rsync -rD /dev/pts root@172.25.254.121:/mnt/  同步设备文件

root@172.25.254.121's password: 



  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值