Linux系统中的文件传输

需要配置两台可以相互通信的主机

虚拟机node1 ---> 192.168.2.100

虚拟机node2 ---> 192.168.2.200

实验环境

需要2台主机并且保证这两台主机是可以通信的

systemctl disable firewalld

systemctl stop firewalld

scp命令

scp 本地文件 远程主机用户@远程主机ip:远程主机目录的绝对路径

scp 远程主机用户@远程主机ip:远程主机文件的绝对路径 本地文件

实验步骤:

1.在node1建立实验素材

touch file1

mkdir dir1

2.测试

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

scp file1 root@192.168.2.200:/root/Desktop/

scp -r dir root@192.168.2.200:/root/Desktop/        -r 表示复制目录

scp -q westos root@172.25.254.20:/root/Desktop          -q 传输文件时不显示进度

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

scp root@192.168.2.200:/root/Desktop/free .

time scp/time rsync   对比传输时间可看出两个命令的区别
rsync和scp命令的对比
node2:
ssh-keygen ## 生成密钥
ssh-copy-id -i /root/.ssh/id_rsa.pub. root@172.25.254.20
3)创建测试脚本
time scp -qr /boot root@172.25.254.20:/root/Desktop
time scp -qr /boot root@172.25.254.20:/root/Desktop
time scp -qr /boot root@172.25.254.20:/root/Desktop
vim check_rsync.sh ##检测rsync的传输时间
time rsync -raCq /boot root@172.25.254.20:/root/Desktop
time rsync -raCq /boot root@172.25.254.20:/root/Desktop
time rsync -raCq /boot root@172.25.254.20:/root/Desktop

 

rsync执行

在node1中建立实验环境


touch /mnt/file{1..3}

ln -s /mnt/westosfile1 /root/westoslee

chown westos.westos /mnt/*

chmod 777 /mnt/*

在node2中建立监控 

 watch -n 1 ls –R1 /mnt/

rsync用法实验


rsync 文件 远程用户@远程主机ip:远程主机目录
rsync 远程用户@远程主机ip:远程主机目录 文件路径
rsync
-r ##复制目录
-l ##复制链接
-p ##复制权限
-t ##复制时间戳
-o ##复制拥有者
-g ##复制拥有组
-D ##复制设备文件
执行命令看效果
rsync -r  /mnt/ root@192.168.2.200:/mnt/ ##同步目录本身其目录中的文件
rsync -r /mnt root@192.168.2.200:/mnt/##只同步目录中的文件
rsync -rl /mnt/ root@192.168.2.200:/mnt/##同步链接
rsync -rlp /mnt/ root@192.168.2.200:/mnt/##同步权限
rsync -rlpog /mnt/ root@192.168.2.200:/mnt ##同步用户组
rsync -rlpogt /mnt/ root@192.168.2.200:/mnt ##同步时间
rsync -rD /dev/pts/ root@192.168.2.200:/mnt ##同步设备文件

 文件的归档压缩

1.文件归档


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

 2.文件的压缩

zip
zip -r mnt.tar.zip mnt.tar #zip格式压缩
unzip mnt.tar.zip #zip格式解压缩
gzip
gzip etc.tar
gzip格式压缩
gunzip etc.tar.gz #gzip格式解压缩

bzip2 etc.tar
#bzip2格式压缩
bunzip2 etc.tar.bz2 #bzip2格式解压缩
xz etc.tar
#xz格式压缩
unxz etc.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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

溪野~~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值