一、文件的传输

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. Java哲学家进餐

    某次操作系统实验存档. 这个哲学家除了吃就是睡.. 哲学家.java: package operating.entity.philosophyeating; import operating.meth ...

  2. Vue 组件间传值

    前言 Vue 作为现在比较火的框架之一,相信您在使用的过程中,也会遇到组件间传值的情况,本文将讲解几种 Vue 组件间传值的几种方法,跟着小编一起来学习一下吧! 实现 注意: 学习本文,需要您对 Vu ...

  3. HAL编译问题

    1 make:进入目录'/opt/FriendlyARM/tiny4412/android/android-4.1.2'make: *** 没有规则可以创建“out/target/product/ge ...

  4. shell编程(二)

    case判断 前面了解了shell编程的if判断,其实除了if判断,还有case判断. case语法: case VAR in case1) command1 ;; case2) command2 ; ...

  5. 深度学习笔记(一):logistic分类【转】

    本文转载自:https://blog.csdn.net/u014595019/article/details/52554582 这个系列主要记录我在学习各个深度学习算法时候的笔记,因为之前已经学过大概 ...

  6. struts2的refreshModelBeforeResult

    首先想介绍的是struts2的原型驱动ModelDriven机制. 所谓的ModelDriven,就是把一个实体类当成页面数据的收集对象.用法看起来像下面这个样子 <span style=&qu ...

  7. Linux 网站文件和数据库全量备份 一键脚本(支持FTP,Google Drive)

    原文连接: https://teddysun.com/469.html 此文为转载,建议查看秋水大神的原文,排版更容易查看,另外,建议查看脚本源码,方便了解脚本运行过程, 脚本已测试,大神的脚本一如既 ...

  8. Ubuntu16.04怎么安装virtualenv虚拟环境

    最近安装virtualenv的python虚拟环境,在网上找了很多,尝试了很多,都有各种问题,最终搞定后,给大家分享下我的过程,希望大家少走弯路. 本次安装是基于Ubuntu16.04Linux版本安 ...

  9. shiro对事务的影响

    记一个 No transaction aspect-managed TransactionStatus in scope 错误的解决方法 昨天出现一个BUG,事务没有加回滚成功,修改管理员密码事务没有 ...

  10. oracle sql - remove a user's all objects

    DECLARE TYPE cst_table_list IS TABLE OF VARCHAR2(40); TYPE cst_list IS TABLE OF VARCHAR2(40); TYPE n ...