linux系统中的远程传输

系统中的文件传输:

1,scp指令,传输较慢:

scp file username@ip:/dir          上传

例如:scp file [email protected]:/root/Desktop

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

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


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


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

例如:scp   [email protected]:/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 [email protected]:/mnt/ 传输到121虚拟机上面但是没有用户组权限时间不对应。

[email protected]'s password:


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

[email protected]'s password:


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

[email protected]'s password:


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

[email protected]'s password:


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

[email protected]'s password:  


rsync -r /mnt [email protected]:/mnt/   仅仅复制内容

rsync -r /mnt/ [email protected]:/mnt/  连同复制本身

同步链接:

[kiosk@foundation21 Desktop]$ ssh [email protected] 连接server虚拟机

[email protected]'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 [email protected]:/mnt/

[email protected]'s password:

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

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

[email protected]'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 [email protected]:/mnt/  查看时候                                                                     ll pts/

[email protected]'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 [email protected]:/mnt/  同步设备文件

[email protected]'s password: 



猜你喜欢

转载自blog.csdn.net/aaaaaab_/article/details/80145272
今日推荐