###########实验环境###########
需要2台主机并且保证这两台主机是可以通信的
systemctl disable firewalld
systemctl stop firewalld ##关掉防火墙 一般不建议使用
#1.scp命令#
scp 本地文件 远程主机用户@远程主机ip:远程主机目录的绝对路径
##从远程用户中复制文件到本地
scp 远程主机用户@远程主机ip:远程主机文件的绝对路径 本地文件
##将本地文件复制给远程用户
实验步骤:
1.在TAB建立实验素材
touch westos
mkdir westosdir
2.测试
a)把本地文件复制到远程主机 (上传)
scp westos root@172.25.254.20:/root/Desktop
scp -r westosdir root@172.25.254.20:/root/Desktop ## -r 表示复制目录
scp -q westos root@172.25.254.20:/root/Desktop ## -q 传输文件时不显示进度
b)把远程文件复制到本地(下载)
scp root@172.25.254.20:/root/Desktop/westos_rhel8 /root/Desktop
c)显示传输时间
time scp ##显示传输时间
rsync和scp命令的对比(实验)
node2:
ssh-keygen ## 生成密钥
ssh-copy-id -i /root/.ssh/id_rsa.pub. root@172.25.254.20
#2.rsync执行命令#
rsync 文件 远程用户@远程主机ip:远程主机目录
rsync 远程用户@远程主机ip:远程主机目录 文件路径
rsync
-r ##复制目录
-l ##复制链接
-p ##复制权限
-t ##复制时间戳
-o ##复制拥有者
-g ##复制拥有组
-D ##复制设备文件
执行命令看效果:
rsync -r root@1.1.1.2:/root/Desktop /mnt ##同步目录本身其目录中的文件
rsync -r root@1.1.1.2:/root/Desktop/ /mnt ##只同步目录中的文件
rsync -rl root@1.1.1.2:/root/Desktop/ /mnt ##同步链接
rsync -rlp root@1.1.1.2:/root/Desktop/ /mnt ##同步权限
rsync -rlpog root@1.1.1.2:/root/Desktop/ /mnt ##同步用户组
rsync -rlpogt root@1.1.1.2:/root/Desktop/ /mnt ##同步时间
rsync -rD root@1.1.1.2:/dev/pts /mnt ##同步设备文件
#3.文件的归档压缩#
(1)文件归档tar
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_rhel8
tar xf etc.tar
tar f etc.tar --get westos_rhel8
tar f etc.tar --delete westos_rhel8
tar xf etc.tar -C /root/Desktop
(2)文件的压缩
Linux系统默认支持zip、gzip、bzip2、xz四种文件压缩格式
(1)zip
zip -r mnt.tar.zip mnt.tar #zip格式压缩
unzip mnt.tar.zip #zip格式解压缩
(2)gzip
gzip mnt.tar #gzip格式压缩
gunzip mnt.tar.gz #gzip格式解压缩
(3)bzip2
bzip2 mnt.tar #bzip2格式压缩
bunzip2 etc.tar.bz2 #bzip2格式解压缩
(4)xz
xz mnt.tar #xz格式压缩
unxz mnt.tar.xz #xz格式解压缩
(3)打包(tar)+压缩
(1)gzip
tar zcf etc.tar.gz /etc
tar zxf etc.tar.gz
(2)bzip2
tar jcf etc.tar.bz2 /etc
tar jxf etc.tar.bz2
(3)xz
tar Jcf etc.tar.xz /etc
tar Jxf etc.tar.xz
不支持zip模式