1.文件传输
(两台主机保证其可通信,可以互ping)
1)scp命令
-
scp 本地文件 远程主机用户
-
实验
-
scp file [email protected]:/root/Desktop ##远程传送文件
-
scp -r dir [email protected]:/root/Desktop ##远程传送目录
-
scp -q file [email protected]:/root/Desktop ##传送文件不显示进度
-
-
scp [email protected]:/root/Desktop/file . ##将虚拟机文件下载到当前
2)对比rsync和scp区别:
-
scp ##完整备份
-
rsync ##增量备份
-
检测增量备份时间与完整备份时间
-
rsync参数:-aCq ##a 任意 C 增量检测 q 不显示进度
-
##实验脚本##
-
scp:
-
time scp -qr /boot [email protected]:/root/Desktop
-
time scp -qr /boot [email protected]:/root/Desktop
-
time scp -qr /boot [email protected]:/root/Desktop
-
-
rsync:
- time rsync -raCq /boot [email protected]:/root/Desktop
- time rsync -raCq /boot [email protected]:/root/Desktop
- time rsync -raCq /boot [email protected]:/root/Desktop
-
3)rsync用法:
- rsync file [email protected]:/root/Desktop/ ##批量复制指令
- rsync 远程用户@远程主机ip:远程主机目录 文件路径 ##从远程主机下载文件
- 复制前先建立免密连接,加快复制速度
- 建立实验环境
- ##实验##
-westos_node1中watch -n 1 ls -lR /root/desktop
在真机中 touch westosdir/westosfile{1…5}
ln -s /root/westos/Desktop/westosdir/westosfile1 westosdir/test 在真机中执行传送命令查看效果
-
rsync ##批量复制
-
-r ##复制目录
-
-l ##复制连接
-
-p ##复制权限
-
-o ##复制所有人
-
-g ##复制所有组
-
-t ##复制时间戳
-
-D ##复制设备文件
-
2.文件的归档压缩
1)文件归档
-
tar
-
c ##创建
-
f ##名称
-
x ##解档
-
v ##显示过程
-
t ##查看内容
-
r ##向归档文件添加文件
-
-P ##donot remove “/”,解档至绝对路径
-
–get ##指定文件解档
-
–delete ##指定文件删除
-
-C ##指定解档路径
-
2)文件压缩
-
zip格式压缩
- zip -r etc.tar.zip ect.tar
- unzip etc.tar.zip
-
gzip压缩格式
- gzip etc.tar
- gunzip etc.tar.gz
-
bzip2压缩格式
- bzip2 etc.tar
- bunzip2 ect.tar.bz2
-
xz压缩格式
- xz etc.tar
- unxz etc.tar.xz
-
du -sh etc.tar.zip ##查看大小
3)打包压缩一步完成
- gzip压缩打包: tar zcf etc.tar.gz /etc/
- bzip2压缩打包 tar jcf ect.tar.bz2 /etc/
- xz压缩打包 tar Jcf ect.tar.xz /etc/
- gzip解压 tar zxf ect.tar.gz
- bzip2解压 tar jxf ect.tar.bz2
- xz解压 tar Jxf ect.tar.xz