一、文件的传输

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. Let Her Go

    转自:https://www.zhihu.com/question/29255072/answer/43962611 [MV]Passenger-Let Her Go-高清MV在线播放 版本一 Let ...

  2. mysql 手动安装和管理

    版本:5.7.10 my.ini简单配置 [client] default-character-set=utf8 [mysqld] port = 3306 basedir =D:/programs/M ...

  3. 前端学习之JavaScript中的 NaN 与 isNaN

    NaN NaN 即 Not a Number ,不是一个数字. 在 JavaScript 中,整数和浮点数都统称为 Number 类型 .除此之外,Number 类型还有一个很特殊的值,即 NaN . ...

  4. 解决Linux 下server和client 通过TCP通讯:accept成功接收却报错的问题

    今天在写简单的TCP通讯例子的时候,遇到了一个问题:server 和client能够连接成功,并且client也能够正常发送,但server就是接收不到,在网上搜索一番后,终于解决了问题.在这里整理如 ...

  5. crontab + rsyncd同步方案

    目的主机: rsync --daemon [root@iZ23ohdbxmrZ ~]# vim /etc/rsyncd.conf #global settingsport = 873pid file= ...

  6. shell编程(一)

    转义和引用 引入问题:之前我们知道了变量名前面加上$符号代表引用变量,但是如果我现在就需要打印出$符号该怎么办呢?想想我们在python中怎么做的,答案是转义. 转义 Shell中有两种字符一种是普通 ...

  7. JS时间和字符串的相互转换 Date+String

    1.js字符串转换成时间 1.1方法一:输入的时间格式为yyyy-MM-dd function convertDateFromString(dateString) { if (dateString) ...

  8. valid 校验方式

    校验参数方法:1.最简单的方式是,使用Java bean注解校验(如 @NotEmpty...)2.适合复杂点的自定义校验(推荐) 2.1 先定义一个校验接口: public interface Va ...

  9. jsp判断以某个字母开头

    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ tag ...

  10. java堆排序(大根堆)

    实现堆排序的算法思路是先创建堆,也就是从叶子节点起对每一层的孩子节点及其对应位置的父亲节点进行比较,较大的孩子节点替换较小的父亲节点,一级一级比较替换,就创建出了大根堆,小根堆反之.创建好大根堆以后, ...