一、实验环境
需要两台主机并且保证这两台主机是可以通信的
lyx_client:172.25.254.105
linux_server:172.25.254.205
关闭火墙!!
systemctl disable --now firewalld
关闭火墙后要重新加载下
二、scp & rsync 命令
1. scp命令
scp file [email protected]:/root/Desktop | 复制文件给远程文件 |
---|---|
scp -r dir [email protected]:/root/Desktop | -r 表示复制目录给远程主机 |
scp -q file [email protected]:/root/Desktop | -q 传输文件时不显示进度 |
先在一台主机上建立实验素材:
scp file [email protected]:/root/Desktop(复制文件给远程文件)
scp -r dir [email protected]:/root/Desktop ( -r 表示复制目录给远程主机)
scp -q file [email protected]:/root/Desktop ( -q 传输文件时不显示进度)
scp [email protected]:/root/Desktop/file /root/Desktop (把远程主机里的文件复制到本地)
2.rsync命令
rsync -r | 复制目录 |
---|---|
rsync -l | 复制链接 |
rsync -p | 复制权限 |
rsync -t | 复制时间戳 |
rsync -o | 复制拥有者 |
rsync -g | 复制拥有组 |
rsync -D | 复制设备文件 |
rsync -r /mnt [email protected]:/root/Desktop (同步目录本身其目录中的文件)
rsync -r /mnt/ [email protected]:/root/Desktop (同步目录本身其目录中的文件)
rsync -rl /mnt [email protected]:/root/Desktop/ (同步链接 )
rsync -rp [email protected]:/root/Desktop/ /mnt (同步权限)
rsync -ro /mnt [email protected]:/root/Desktop/ (同步用户 )
rsync -rg /mnt [email protected]:/root/Desktop/ (同步用户组 )
rsync -rt /mnt [email protected]:/root/Desktop/ (同步时间 )
rsync -rD /mnt [email protected]:/dev/pts (同步设备文件 )
3.scp与rsync命令的对比
1)先建立实验素材:
dd if=/dev/zero of=/root/Desktop/westosfile1 bs=1M count=10
dd=截取;if=inputfile;of=outputfile;bs=blocksize;count=块的个数
2)在主机之间建立免密登陆使远程文件传输可以直接执行 :
ssh-copy-id -i /root/.ssh/id_rsa.pub. [email protected] 给远程主机上锁
这时在向远程主机传输文件时就不用每次都登密码了
3)创建测试脚本
4)执行(检测传输时间)
scp:
以上执行结果可以看出,scp三次执行时间差不多
rsync:
以上执行结果可以看出,rsync三次执行时间后两次远远小于前两次
三、文件的归档与压缩
1.文件的归档
tar c | 创建 |
---|---|
tar f | 指定文件名称 |
tar x | 解档 |
tar v | 显示过程 |
tar t | 查看 |
tar r | 向归档文件中添加文件 |
tar --get | 解档指定文件 |
tar --delete | 删除指定文件 |
tar -C | 指定解档路径 |
tar cf bin.tar
tar tf bin.tar
2. 文档的压缩
- zip格式
- gz格式
- bz2格式
- xz格式
3.归档压缩一步完成
gz:
bz2:
xz: