实验环境

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

linux_westos  : 172.25.254.10

westos_lue :  172.25.254.20

systemctl disable  firewalld

systemctl stop firewalld

1.scp命令

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

 实验:

1.在172.25.254.10主机中建立实验素材

touch westosfile

mkdir westosdir

touch westosdir/test{1..5}

echo "hello" > westosfile

2.测试

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

scp  westosfile   root@172.25.254.20:/root/Desktop

scp -r westosdir root@172.25.254.20:/root/Desktop  -r 表示复制 目录

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

scp  westosfile   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/testdir   /root/Desktop

2.rsync

  •   rsync和scp命令的对比

实验素材:

1)172.25.254.10:(du -sh *)

dd if=/dev/zero of=/root/Desktop/westosfile1 bs=1M count=10

dd=截取

if=inputfile

of=outputfile

bs=blocksize

count=个数

dd if=/dev/zero of=/root/Desktop/westosfile2 bs=1M count=20

dd if=/dev/zero of=/root/Desktop/westosfile3 bs=1M count=30

2)在主机之间建立免密登陆使远程文件传输可以直接执行

rhel8中:

ssh-keygen  生成密钥

ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.25.254.20

3)创建测试脚本

vim /mnt/test_scp.sh    检测scp传输时间

time scp -qr /root/Desktop root@172.25.254.20:/root/Desktop

time scp -qr /root/Desktop root@172.25.254.20:/root/Desktop

time scp -qr /root/Desktop root@172.25.254.20:/root/Desktop

vim /mnt/test_rsync.sh  检测rsync的传输时间

time rsync -racq /root/Desktop root@172.25.254.20:/root/Desktop

time rsync -racq /root/Desktop root@172.25.254.20:/root/Desktop

time rsync -racq /root/Desktop root@172.25.254.20:/root/Desktop

4)执行 

scp

sh /mnt/test_scp.sh

real 0m1.334s

user 0m0.210s

sys 0m0.490s 第一次系统执行时间

real 0m1.642s

user 0m0.412s

sys 0m0.383s 第二次系统执行时间

real 0m1.586s

user 0m0.309s

sys 0m0.497s 第三次系统执行时间

以上执行效果我们可以看出scp三次执行时间几乎一致

rsync执行

sh /mnt/test_rsync.sh

real 0m1.603s

user 0m0.399s

sys 0m0.557s 第一次系统执行时间

real 0m0.329s

user 0m0.012s

sys 0m0.010s 第二次系统执行时间

real 0m0.348s

user 0m0.014s

sys 0m0.022s 第三次系统执行时间

以上执行效果我们可以看出rsync三次执行时间后两次远远小与第一次

  • rsync用法

rsync  文件 远程用户@远程主机ip:远程主机目录

rsync 远程用户@远程主机ip:远程主机目录 文件路径

rsync
        -r 复制目录

-l 复制链接

-p 复制权限

-t 复制时间戳

-o 复制拥有者

-g 复制拥有组

-D 复制设备文件

实验环境

在linux_westos中

watch -n 1 ls -lR /mnt/

在westos_lue中

touch westosfile{1..5}

ln -s /root/Desktop/westosfile1 /root/Desktop/westoslink

chown westos.westos *(chown westos /root/Desktop *)

chmod 777 *

执行命令看效果:(linux_westos)

rsync  -r root@172.25.254.20:/root/ Desktop  /mnt同步目录本身其目录中的文件

rsync  -r root@172.25.254.20:/root/ Desktop/ /mnt 只同步目录中的文件

rsync  -rl root@172.25.254.20:/root/ Desktop /mnt    同步链接

rsync  -rlp root@172.25.254.20:/root/Desktop /mnt   同步权限

rsync  -rlpog  root@172.25.254.20:/root/Desktop /mnt   同步用户组

rsync  -rlpogt   root@172.25.254.20:/root/Desktop /mnt   同步时间

rsync -rD /dev/pts root@172.25.254.20: /dev/pts  /mnt 同步设备文件

rsync  -r root@172.25.254.20:/root/ Desktop  /mnt同步目录本身其目录中的文件

rsync  -r root@172.25.254.20:/root/ Desktop/ /mnt 只同步目录中的文件

rsync  -rl root@172.25.254.20:/root/ Desktop /mnt    同步链接

rsync  -rlp root@172.25.254.20:/root/Desktop /mnt   同步权限

rsync  -rlpog  root@172.25.254.20:/root/Desktop /mnt   同步用户组

rsync  -rlpogt   root@172.25.254.20:/root/Desktop /mnt   同步时间

rsync -rD /dev/pts root@172.25.254.20: /dev/pts  /mnt 同步设备文件

文件的归档压缩

1.文件归档

tar

c 创建

f 指定文件名称

x 解档

t 查看

-v 显示过程

r 向归档文件中添加文件

--get 解档指定文件

--delete 删除指定文件

-C 指定解档路径

实验步骤:

tar cf mnt.tar /mnt/

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

实验素材

tar cf mnt.tar /mnt/

tar tvf mnt.tar

tar rf mnt.tar westosfile

tar xf mnt.tar

tar f mnt.tar  --get westosfile

tar f mnt.tar --delete westosfile

tar xf mnt.tar -C /root/Desktop

2.文件的压缩

zip

zip -r  mnt.tar.zip mnt.tar     zip格式压缩

unzip tar mnt.zip                 zip格式解压缩

zip -r  mnt.tar.zip mnt.tar zip格式压缩

unzip tar mnt.zip                 zip格式解压缩

gzip

gzip mnt.tar               gzip格式压缩

gunzip mnt.tar.gz       gzip格式解压缩

bzip2 mnt.tar             bzip2格式压缩

bunzip2 mnt.tar.bz2    bzip2格式解压缩

xz mnt.tar                    xz格式压缩

unxz mnt.tar.xz            xz格式解压缩

gzip mnt.tar gzip格式压缩

gunzip mnt.tar.gz       gzip格式解压缩

bzip2 mnt.tar             bzip2格式压缩

bunzip2 mnt.tar.bz2    bzip2格式解压缩

xz mnt.tar                    xz格式压缩

unxz mnt.tar.xz            xz格式解压缩

3.tar+压缩

gzip

tar zcf mnt.tar.gz /mnt

tar zxf mnt.tar.gz  解档

bzip2

tar jcf mnt.tar.bz2 /mnt

tar jxf mnt.tar.bz2

xz

tar Jcf mnt.tar.xz /mnt

tar Jxf mnt.tar.xz

Linux系统中的文件传输(scp命令,rsync命令)相关推荐

  1. linux系统中的文件传输

    Linux系统中的文件传输 1 实验环境 2 scp命令 3 rsync命令 3.1 rsync和scp命令对比 3.2 rsync命令用法 4 文件的归档压缩 4.1 文件归档 4.2 文件压缩 4 ...

  2. linux系统中加密文件传输助手,Linux 下的安卓文件传输助手!

    如果你尝试在 Ubuntu 下连接你的安卓手机,你也许可以试试 Linux 下的安卓文件传输助手.本质上来说,这个应用是谷歌 macOS 版本的一个克隆.它是用 Qt 编写的,用户界面非常简洁,使得你 ...

  3. 运维大法之Linux系统中的文件传输

    1.scp和rsync命令 实验环境 需要2台主机并且保证这两台主机是可以通信的 ①localhost.localdomain 172.25.254.10 ②node.westos.com 172.2 ...

  4. Linux系统中的文件传输(scp和rsync命令的使用)

    一.实验环境 两台可以通信的主机 rhel7: 192.168.1.20 rhel8: 192.168.1.10 二.scp命令 scp 本地文件 远程主机用户@远程主机ip:远程主机目录 scp 远 ...

  5. Linux系统中的文件传输优化

    目录 一.实验环境 二.scp 命令 1.在rhel7中建立实验素材 2.测试 三.rsync命令 四.scp与 rsync的比较 五. 文件的归档与压缩 1.文件归档 2.文件的压缩 3.tar+压 ...

  6. 在linux系统中创建文件夹,Linux系统中创建文件夹命令详解

    Linux系统中创建一个新的文件夹我们可以使用命令来执行,下面由学习啦小编为大家整理了Linux系统中创建文件夹命令详解,希望对大家有帮助! Linux系统中创建文件夹命令详解 一.mkdir命令使用 ...

  7. linux命令打包文件,Linux系统中打包文件的命令详解

    linux系统中遇到要打包文件的时候我们该使用什么命令呢?下面由秋天网 Qiutian.ZqNF.Com小编为大家整理了linux系统中打包文件的命令详解的相关知识,希望对大家有帮助! linux系统 ...

  8. Android 系统(68)---使用Xshell在Windows系统和Linux系统之间进行文件传输

    使用Xshell在Windows系统和Linux系统之间进行文件传输 Windows系统在安装虚拟机centos系统之后,如何进行两者之间的文件传输和互操作,或者如何在Windows端使用Xshell ...

  9. 将windows系统主机上的文件拷贝到Linux系统中;将Linux系统中的文件粘贴到Windows主机中

    本篇文章主要实现将windows主机上的文件复制到Linux服务器上,这里为了方便演示,我举例放在C盘中的一个test101.py文件,现在我要将它放在Linux系统的home下的shao目录下. 首 ...

最新文章

  1. 人工智能学习框架TensorFlow渐近分析
  2. hdu1247 字典树或者hash
  3. 需要多快的速度,才能在抽走桌布之后保持桌面物体不掉?
  4. 控制台发送get命令_.NET Core使用命令行参数库构建控制台应用程序
  5. apktool重新打包,error:No resource identifier found for attribute ‘compileSdkVersionCodename‘ in package
  6. vs 设置起始页不见了_发朋友圈屏蔽爸妈,结果不小心设置成了仅家人可见...场面一发不可收拾哈哈哈哈!...
  7. 我都服了,为啥上游接口返回的汉字总是乱码?
  8. python算法有多少个_Python算法比较两个排序的列表并计算多少个...
  9. 组件端Apollo配置放到NAS中
  10. HDU2015 偶数求和【入门】
  11. python编程教学软件-Python编程教学app
  12. windows phone 切换多语言时,商店标题显示错误的问题
  13. ecshop添加404页面
  14. 生态系统服务——食物生产功能分布数据
  15. 微信经典飞机大战素材
  16. x264代码剖析笔记
  17. 阿里云弹性计算研发团队如何从0到1自建SRE体系
  18. 电子设计教程30:温度滞回控制系统
  19. eclipse如何配置工作环境
  20. Redis 核心知识——01

热门文章

  1. kubesphere k8s 安装Fluentd,带elasticsearch插件
  2. Camtasia Studio2023电脑屏幕录制软件免费版
  3. 简约高端大气PPT模板
  4. excel排除除以0的错误
  5. Execution failed for task ‘:app:kaptDebugKotlin‘. > A failure occurred while executing org.jetbrains
  6. VSCode正则搜索中文字符
  7. 【Windows Server 2019】DNS服务器的配置与管理——DNS反向解析
  8. 梯度下降法和泰勒公式
  9. PlantUML 快速入门(二) UML 时序图
  10. 大数据项目实战教程:使用SparkSQL+Hbase+Oozie构建企业级用户画像