linux文件的远程传输(scp+rsync),压缩,打包

systemctl disable firewalld
systemctl stop firewalld

1.scp命令

scp :所有的文件都会传输
scp 本地文件 远程主机用户@远程主机ip:远程主机目录的绝对路径
scp 远程主机用户@远程主机ip:远程主机文件的绝对路径 本地文件

-r  传输目录
-q  不显示进度

a)把本地文件复制到远程主机 (上传)

scp westos [email protected]:/root/Desktop
scp -rq /boot [email protected]:/root/Desktop## -r 表示复制目录 ## -q 传输文件时不显示进度
在这里插入图片描述在这里插入图片描述

b)把远程文件复制到本地(下载)

scp [email protected]:/root/Desktop/westos /root/Desktop

2.rsync

a) rsync和scp命令的对比

1.rsync在第每次传输的时候会检测缺失,只传输没有的,花费时间少,但需要加上特定的参数,才不会忽略一些字符设备等特殊文件

在执行time命令的时候已在22主机中对34主机做了加密,可以免密登录

time scp -qr /root/Desktop [email protected]:/root/Desktop
2.检测scp的传输时间
执行效果我们可以看出scp三次执行时间几乎一致
在这里插入图片描述

time rsync -raCq /root/Desktop [email protected]:/root/Desktop
##检测rsync的传输时间
执行效果我们可以看出rsync三次执行时间后两次远远小与第一次
在这里插入图片描述

b)rsync用法

rsync 文件 远程用户@远程主机ip:远程主机目录
rsync 远程用户@远程主机ip:远程主机目录 文件路径

扫描二维码关注公众号,回复: 12418688 查看本文章

rsync

-r	##复制目录
-l	##复制链接
-p	##复制权限
-t	##复制时间戳
-o	##复制拥有者
-g	##复制拥有组
-D	##复制设备文件
-q 不显示进度

同步目录?同步目录本身?及目录里的文件?在这里插入图片描述

rsync -r [email protected]:/root/Desktop /mnt ##同步目录本身其目录中的文件
在这里插入图片描述

rsync -r [email protected]:/root/Desktop/ /mnt ##只同步目录中的文件

在这里插入图片描述

rsync -rlpogt [email protected]:/root/Desktop/ /mnt ##同步时间;同步链接,同步用户组;同步权限
rsync -rD [email protected]:/dev/pts /mnt ##同步设备文件

文件的归档压缩

打包后传输更快

1.文件归档

tar

c	##创建
f	##指定文件名称
x	##解档
v	##现实过程
t	##查看
r	##向归档文件中添加文件
--get##解档指定文件
--delete##删除指定文件
-C	##指定解档路径

P ##don’t remove “/”

tar cf etc.tar /etc/ ###归档
tar tf etc.tar
在这里插入图片描述

tar rf etc.tar westos
在这里插入图片描述

tar xf etc.tar #解档
在这里插入图片描述

tar f etc.tar --get westos
tar f etc.tar --delete westos
tar xf etc.tar -C /root/Desktop

在这里插入图片描述

2.文件的压缩

zip

打包后压缩
tar cf mnt.tar /mnt/
zip -r mnt.tar.zip mnt.tarzip格式压缩
unzip mnt.tar.zip zip格式解压缩

gzip

gzip mnt.tar gzip格式压缩
gunzip mnt.tar.gz gzip格式解压缩

bzip

bzip2 mnt.tar bzip2格式压缩
bunzip2 etc.tar.bz2 bzip2格式解压缩

xz

xz mnt.tar xz格式压缩
unxz mnt.tar.xz xz格式解压缩

3.tar+压缩(打包加压缩)

gzip

tar zcf etc.tar.gz /etc
tar zxf etc.tar.gz ###解压缩

bzip2

tar jcf etc.tar.bz2 /etc
tar jxf etc.tar.bz2

xz

tar Jcf etc.tar.xz /etc
tar Jxf etc.tar.xz

猜你喜欢

转载自blog.csdn.net/ninimino/article/details/109480826
今日推荐