一,实验环境:需要两台主机并且这两台主机是可以互相通信的
二,systemctl disable firewalld 开机时不启动防火墙
systemctl stop firewalld 关闭防火墙
三,实验步骤
1.在nodaB中建立文件和目录
touch westos mkdir westosdir
2.scp命令
scp westos root@192.168.155.70:/root/Desktop 把文件westos从主机上传70主机桌面
scp -r westosdir root@192.168.155.70:/root/Desktop 把目录westosdir从主机上传70这台主机
scp 本地文件 远程主机用户@远程主机ip:远程主机目录的绝对路径
scp root@192.168.155.70:/root/Desktop/westosfile . 把70这台住据上的文件传送到这台主机桌面
scp -r root@192.168.155.70:/root/Desktop/westostest . 把70这台主机的目录westostest传送到当前主机上
scp 远程主机用户@远程主机ip:远程主机文件的绝对路径 本地文件
scp -q westos root@192.168.155.70:/root/Desktop 传输文件时不显示进度
3,rsync命令
rsync -r root@192.168.155.80:/mnt /mnt 同步目录本身其目录中的文件
rsync -r root@192.168.155.80:/mnt/ /mnt/ 只同步目录中的文件
rsync -lr root@192.168.155.80:/mnt/ /mnt/ 同步链接
rsync -lpr root@192.168.155.80:/mnt/ /mnt/ 同步权限
rsync -lgpr root@192.168.155.80:/mnt/ /mnt/ 同步用户组
rsync -lgtopr root@192.168.155.80:/mnt/ /mnt/ 同步时间
rsync -lgtoDpr root@192.168.155.80:/mnt/ /mnt/ 同步设备文件
![](https://i-blog.csdnimg.cn/blog_migrate/f4ac87853bafcc6a069e049540018b54.png)
4,测试时间
四,文件的归类压缩
tar cf etc.tar /etc/ 归档目录
[root@westos_student50 Desktop]# tar tf etc.tar 查看归档的内容
[root@westos_student50 Desktop]# tar rf etc.tar file 把桌面上的文件file放入归档之中
[root@westos_student50 Desktop]# tar xf etc.tar 解压归档
[root@westos_student50 Desktop]# tar f etc.tar --get file 从归档中拿出一个文件file
[root@westos_student50 Desktop]# tar f etc.tar --delete file 删除归档中的file
[root@westos_student50 Desktop]# tar xf etc.tar -C /mnt/ 解开归档放入指定位置
tar --get 解档指定文件
--delete 删除指定文件
-C 指定解档路径
-P don’t remove “/”
2,文件的压缩和解压
du -sh 查看文件大小
[root@westos_student50 Desktop]# tar cf westos.tar /etc/ 建立归档文件
tar: Removing leading `/' from member names
[root@westos_student50 Desktop]# du -sh westos.tar 查看归档文件大小
28M westos.tar
[root@westos_student50 Desktop]# zip -r westos.tar.zip westos.tar 压缩westos.tar归档文件
adding: westos.tar (deflated 75%)
[root@westos_student50 Desktop]# du -sh westos.tar.zip 查看压缩后大小
7.4M westos.tar.zip
[root@westos_student50 Desktop]# rm -rf westos.tar 删除
[root@westos_student50 Desktop]# unzip westos.tar.zip 解压westos.tar归档文件
Archive: westos.tar.zip
inflating: westos.tar
[root@westos_student50 Desktop]# du -sh westos.tar
28M westos.tar
[root@westos_student50 Desktop]# rm -rf westos.tar.zip
[root@westos_student50 Desktop]# gzip westos.tar 压缩westos.tar归档文件
[root@westos_student50 Desktop]# du -sh westos.tar.gz
6.9M westos.tar.gz
[root@westos_student50 Desktop]# gunzip westos.tar.gz 解压文件
[root@westos_student50 Desktop]# bzip2 westos.tar 压缩westos.tar归档文件
[root@westos_student50 Desktop]# du -sh westos.tar.bz2
5.4M westos.tar.bz2'
[root@westos_student50 Desktop]# bunzip2 westos.tar.bz2 解压
[root@westos_student50 Desktop]# du -sh westos.tar
28M westos.tar
[root@westos_student50 Desktop]# xz westos.tar 压缩westos.tar归档文件
[root@westos_student50 Desktop]# du -sh westos.tar.xz
4.6M westos.tar.xz
[root@westos_student50 Desktop]# unxz westos.tar.xz 解压
[root@westos_student50 Desktop]# du -sh westos.tar 查看归档文件大小
28M westos.tar
[root@westos_student50 Desktop]# rm -rf westos.tar
[root@westos_student50 Desktop]# tar zcf westos.tar.gz /etc 建立归档文件时 压缩
tar: Removing leading `/' from member names
[root@westos_student50 Desktop]# tar jcf westos.tar.bz2 /etc 建立归档文件时 压缩
tar: Removing leading `/' from member names
[root@westos_student50 Desktop]# tar Jcf westos.tar.xz /etc 建立归档文件时 压缩
tar: Removing leading `/' from member names
[root@westos_student50 Desktop]# du -sh * 查看当前目录文件大小
6.9M westos.tar
5.4M westos.tar.bz2
6.9M westos.tar.gz
4.6M westos.tar.xz
[root@westos_student50 Desktop]# tar zxf westos.tar.gz 解压
[root@westos_student50 Desktop]# tar jxf westos.tar.bz2 解压
[root@westos_student50 Desktop]# tar Jxf westos.tar.xz 解压