• 文件的压缩解压与归档


    Windows下的常见压缩格式有.zip和.rar,而Linux下的常见压缩格式有:gz,bzip2,xz,zip等由于压缩算法的不同,所以以上几个压缩后的文件大小各不同。

    一、gzip

    用法:gzip 文件路径 gzip压缩与解压完成后会删除源文件。

    #压缩文件
    [root@centos7 app]$gzip testfile
    #解压文件
    [root@centos7 app]$gunzip testfile.gz
    [root@centos7 app]$gzip -d testfile.gz
    #不解压文件查看源文件
    

    二、bzip2

    用法:bzip2 文件路径

    压缩文件:bzip2 testfile
    解压文件:bzip2 -d testfile.bz
    -k 不删除原文件的情况下解压:bzip2 -dk testfile.bz
    不解压缩查看原文件:bzcat file

    三、xz

    用法:xz 文件路径
    压缩文件:xz testfile
    解压文件:xz -d testfile
    不删除源文件解压:xz -dk testfile
    不解压查看原文件:xzcat file

    四、zip打包压缩

    zip 可以压缩文件,也可以压缩目录并且默认不删除原文件。以上三个无此功能
    压缩文件:zip file
    解压文件:unzip file
    递归处理子目录:zip -r file

    五、tar工具

    tar工具是归档文件不是压缩工具,归档完的文件可能比之前的文件还大一些。并且tar工具对于归档和展开归档并不会删除原文件。

    1.将多个文件创建到指定路径的归档文件,归档文件通常以tar结尾

    [root@centos7 test]$tar -cf guidang.tar dir1 dir2
    

    2.查看归档文件中的文件列表

    [root@centos7 test]$tar -tf guidang.tar
    

    3.展开归档文件

    #默认展开之当前目录
    [root@centos7 test]$tar -xf guidang.tar
    #展开至指定归档,使用大C
    [root@centos7 test]$tar -xf guidang.tar -C /home/root
    

    4.可以使用tar工具对已有的归档文件进行追加
    但是对于归档并压缩的文件不支持追加。

    [root@centos7 test]$tar -rf guidang.tar file 
    

    5.归档并压缩
    归档的文件名,一定要与压缩的文件格式相对应。
    -j-----bzip2
    -z----gzip
    -J----xz

    • 举例
    [root@centos7 test]$tar -Jcf zuoye.tar.xz zuoye/
    
    • tar打包时排除指定目录
      list为需要打包的文件的绝对路径,
      使用-T调用需要打包的列表文件,-X为排除需要打包的文件
    [root@centos7 test]$tar -jcf zuoye.tar.bzip2 -T list -X fei
    
    • 使用tar时将文件进行分割
    -b 1M 分割成1M大小的块,-d以数字的方式进行区分,zuoye指定分割后文件前缀
    [root@centos7 test]$ split  -b 1M -d zuoye.tar.gzip2 zuoye
    [root@centos7 test]$ ls
    zuoye00  zuoye01  zuoye.tar.bzip2
    #将分割的文件合并
    [root@centos7 test]$cat zuoye0* >zuoye.tar.bzip2
    
  • 相关阅读:
    Luogu P1273 有限电视网【树形Dp/树形背包】
    Luogu P1160队列安排【链表/老文搬家】By cellur925
    Luogu P1970 花匠 【线性Dp】 By cellur925
    Luogu P1541 乌龟棋 【线性dp】
    P2885 [USACO07NOV]电话线Telephone Wire——Chemist
    Luogu P3916 图的遍历 【优雅的dfs】【内有待填坑】By cellur925
    状压dp之二之三 炮兵阵地/玉米田 By cellur925
    Luogu P1991 无线通讯网 【最小生成树】
    浅谈并查集 By cellur925【内含题目食物链、银河英雄传说等】
    Luogu P1134 阶乘问题 【数学/乱搞】 By cellur925
  • 原文地址:https://www.cnblogs.com/aubin/p/7276765.html
Copyright © 2020-2023  润新知