一、文件的传输

1.命令:scp

  scp  file  user@ip:/dir    ##把当前系统目录下的文件file复制到另一个系统目录下

  scp  user@ip:/file  dir

2.命令:rsync    ##数据的远程同步 ,可以加快传输速率

  • 常用参数:-r  ##同步目录里面的内容       -p  ##同步权限      -D  ##同步传输设备

-o  ##同步用户                -g  ##同步组信息

-t  ##同步时间戳              -l  ##同步链接

  • 示例:  在主机97下进行的命令rsync -r niu/ root@172.25.254.177:/mnt/的操作:
  [root@localhost mnt]# mkdir niu 

[root@localhost mnt]# touch niu/file{1..3}

[root@localhost mnt]# chmod 777 niu/*

  [root@localhost niu]# chown student.student *
  [root@localhost niu]# ls -l
  total 0
  -rwxrwxrwx. 1 student student 0 Jul 26 08:49 file1
  -rwxrwxrwx. 1 student student 0 Jul 26 08:49 file2
  -rwxrwxrwx. 1 student student 0 Jul 26 08:49 file3
  [root@localhost mnt]# rsync -r niu/ root@172.25.254.177:/mnt/
   在主机177里面进行查看: 
   [root@localhost mnt]# ls -l
   total 0
   -rwxrwxrwx 1 root root 0 Jul 26 09:00 file1
   -rwxrwxrwx 1 root root 0 Jul 26 09:00 file2
   -rwxrwxrwx 1 root root 0 Jul 26 09:00 file3
  • 在97主机下使用rsync -rp niu/ root@172.25.254.177:/mnt/的操作:

[root@localhost mnt]# rsync -rp niu/ root@172.25.254.177:/mnt/

   在177主机下进行测试 :  (文件的权限相同的)
   [root@localhost mnt]# ls -l
   total 0
   -rwxrwxrwx 1 root root 0 Jul 26 09:00 file1
   -rwxrwxrwx 1 root root 0 Jul 26 09:00 file2
   -rwxrwxrwx 1 root root 0 Jul 26 09:00 file3
  • 在97主机下使用rsync -rpogt niu/  root@172.25.254.177:/mnt/的操作:
   [root@localhost niu]# ls -l
   total 0
   -rwxrwxrwx. 1 student student 0 Jul 26 08:49 file1
   -rwxrwxrwx. 1 student student 0 Jul 26 08:49 file2
   -rwxrwxrwx. 1 student student 0 Jul 26 08:49 file3

[root@localhost mnt]# rsync -rpogt niu/ root@172.25.254.177:/mnt/
    root@172.25.254.177's password:

在177主机下测试:

[root@localhost mnt]# ls -l

    total 0
    -rwxrwxrwx 1 student student 0 Jul 26 08:49 file1
    -rwxrwxrwx 1 student student 0 Jul 26 08:49 file2
    -rwxrwxrwx 1 student student 0 Jul 26 08:49 file3
  • 进行链接的传输:

[root@localhost niu]# ln -s file1 /mnt/niu/westos

    [root@localhost niu]# ls -l
    total 0
    -rwxrwxrwx. 1 student student 0 Jul 26 08:49 file1
    -rwxrwxrwx. 1 student student 0 Jul 26 08:49 file2
    -rwxrwxrwx. 1 student student 0 Jul 26 08:49 file3
    lrwxrwxrwx. 1 root    root    5 Jul 26 09:28 westos -> file1
    [root@localhost mnt]# rsync -rl niu/ root@172.25.254.177:/mnt/
    root@172.25.254.177's password:
  • 进行设备文件的传输:
    [root@localhost mnt]# ls /dev/pts/
     0  ptmx
    [root@localhost mnt]# rsync -rD /dev/pts/ root@172.25.254.177:/mnt/
    root@172.25.254.177's password:
    在177主机下:

[root@localhost mnt]# ls

     0  ptmx

二、归档

  • 作用:可以加快不同系统之间文件的传输,使一个目录或多个文件打包为一个文件,方便传输。(归档不代表剪切)
  • 命令:tar
  • 参数:-c   ## 创建      -v   ## 显示过程      -f   ## 指定归档的文件名称

-t   ## 查看归档文件内容       -r    ## 添加文件到归档中

--get file  ## 解档指定文件    --delete  file   ##删除归档中文件

-C    dir   ## 指定解档的目录

  • 示例:etc.tar的创建和查看结果

  • 添加file文件到etc.tar归档中:
  
  
  • 归档文件的拿出(默认到当前目录下):
  
  • 解档:使档案里的文件全部拿出、解档到固定目录
  

  

三、文件的压缩

【1】zip

格式:zip -r xxx.tar.zip  xxx.tar   压缩

unzip  xxx.tar.zip    解压

示例:

 
 

打包和压缩后的文件的大小:

  [root@localhost Desktop]# ls
  etc.tar  etc.tar.zip
  [root@localhost Desktop]# du -sh *
  30M    etc.tar
  16M    etc.tar.zip

【2】gz

  • 格式:gzip  xxx.tar   压缩

gunzip  xxx.tar.gz  解压

tar zcf  xxx.tar.gz /etc/    打包+压缩

tar zxf  xxx.tar.gz  解压

  • 示例:(在压缩和解压过程中,只能产生一个 )
 
 
  • 打包和压缩后的文件的大小:
  [root@localhost Desktop]# du -sh etc.tar
  30M    etc.tar
  [root@localhost Desktop]# du -sh etc.tar.gz
  8.4M    etc.tar.gz

【3】bz2

  • 格式:bzip2  xxx.tar   压缩

bunzip2   xxx.tar.bz2  解压

tar jcf   xxx.tar.bz2  /etc/   打包+解压

       tar jxf   xxx.tar.bz2  解压
  • 示例:
  
  

【4】xz

  • 格式:xz  xxx.tar   压缩

unxz  xxx.tar.xz  解压

tar  Jcf   xxx.tar.xz   /etc/   打包+解压

       tar Jxf  xxx.tar.xz  解压
  • 示例:
  
  

注释:【2】【3】【4】解压打包可以一步完成

Linux文件在系统中传输的更多相关文章

  1. linux、windows系统间传输文件

    日常工作中经常涉及到系统间的文件传输,下面就简单说一下常用的方法   linux--windows      工具:winscp.SecureCRT.Zmodem(sz, rz)   linux--l ...

  2. Linux文件虚拟机系统只读Read-only file system的快速解决方法

    问题描述:上周公司的私有云(底层架构是Openstack+KVM,目前稳定性还不够好,开发团队在改进中)一个计算节点挂掉,之后恢复后发现这个计算节点的所有Linux系统都变成只读了,复制文件提示:Re ...

  3. android 怎样内置/预置/预编译文件(运行程序,应用程序,apk, jar, lib 等随意文件)到系统中

    方法一:  如果要内置的软件名称为iperf.exe 1. 将iperf.exe放到Codebase的随意一个文件夹下(该文件夹必须可以在搜索Android.mk时被搜索到),比方system/ipe ...

  4. 在Linux和Windows系统中输出目录结构

    前言 一直以来就想在写文章时,能以文本形式(而不是截图)附上项目的目录结构,今天终于知道怎么操作了,在这分享一下. Linux 首先说下Linux上输出目录结构的方法. yum安装tree 需要支持t ...

  5. 加载XML文件到系统中

    using System;using System.Data;using System.IO;using System.Xml;using System.Collections.Generic; na ...

  6. Linux Shell: 统计系统中占用Swap 的程序PID和占用大小

    #!/bin/bash  SUM=0 OVERALL=0 for DIR in `find /proc/ -maxdepth 1 -type d -regex "^/proc/[0-9]+& ...

  7. Xshell6远程访问linux及Xftp6远程针对linux系统中文件操作(附图文详解)

    1.首先我们需要先做好前期准备工作,需要到XManager6官网上将Xshell及Xftp下载并安装,安装过程一直下一步就好了.这里是其官网:http://www.xshellcn.com/.安装完成 ...

  8. Linux系统中cgroup功能介绍

    1  Cgroups简介 1.1 What are cgroups ? Cgroups(控制组)是Linux内核的一个功能,用来限制.统计和分离一个进程组的资源(CPU.内存.磁盘输入输出等).换句话 ...

  9. Linux文件传输协议2019-7-9

    FTP(file transfer Protocol)是一种在互联网中进行文件传输的协议,基于客户端/服务器模式,默认使用20.21号端口,其中端口20(数据端口)用于数据传输,端口21(命令端口)用 ...

随机推荐

  1. 在python3下使用OpenCV 抓取摄像头图像提取蓝色

    工作中需要对摄像头进行调试, Python平台大大提高调试效率. 从网找到段代码, 可以从摄像头图像中抠出蓝色. import cv2 import numpy as np cap  = cv2.Vi ...

  2. OpenStack之Keystone模块

    一.Keystone介绍 OpenStack Identity(Keystone)服务为运行OpenStack Compute上的OpenStack云提供了认证和管理用户.帐号和角色信息服务,并为Op ...

  3. vim 中查询和转换编码

    vim中查询修改文件编码格式 set fileencoding 查看现在文本的编码 :set fenc=编码 转换当前文本的编码为指定的编码 :set enc=编码 以指定的编码显示文本,但不保存到文 ...

  4. mac下ssh到远程服务器时中文乱码

    前言:mac本地的语言环境为英文,远程是支持中文的, 问题: 一开始是在iterm2下登录远程服务器更新数据库时发现中文注释不能正常显示,以为是iterms2下设置有问题,使用系统自带的termina ...

  5. centos7配置安装redis

    关闭防火墙:systemctl stop firewalld.service #停止firewallsystemctl disable firewalld.service #禁止firewall开机启 ...

  6. .NET Framework 系统要求

    .NET Framework 3.5对操作系统的要求 .NET Framework 4 对操作系统的要求 .NET Framework 4.5对操作系统的要求

  7. 记数排序 & 桶排序 & 基数排序

    为什么要写这样滴一篇博客捏...因为一个新初一问了一道水题,结果就莫名其妙引起了战斗. 然后突然发现之前理解的桶排序并不是真正的桶排序,所以写一篇来区别下这三个十分相似的排序辣. 老年菜兔的觉醒!!! ...

  8. spark SQL学习(案例-统计每日uv)

    需求:统计每日uv package wujiadong_sparkSQL import org.apache.spark.sql.{Row, SQLContext} import org.apache ...

  9. 创建Jmeter中使用的jar包中的工具类方法

    1. 在IDEA中新建一个maven工程. 2. 编写工具类方法,如加密算法.此处以加法为例. package DemoTest; public class DemoClass{ public int ...

  10. 查看linux 之mysql 是否安装的几种方法

    转自:https://jingyan.baidu.com/album/86112f1378bf282737978730.html?picindex=2 linux下怎么启动mysql服务 https: ...