• Linux——文件目录压缩/解压缩



    文件目录压缩/解压缩

    文件压缩/解压缩 ------ gzip/bzip2/xz

    gzip *.gz

    压缩:

    [root@node01 ~]# gzip /file/1.txt

    [root@node01 ~]# file /file/1.txt.gz
    /file/1.txt.gz: gzip compressed data, was "1.txt", from Unix, last modified: Mon Apr 10 15:22:52 2017

    解压缩:

    [root@node01 ~]# gzip -d /file/1.txt.gz

    bzip2 *.bz2

    centos7 下好多软件都不带,当然也没有bzip2,于是我们只能下载安装了
    yum -y install bzip2.x86_64

    压缩:

    [root@node01 ~]# bzip2 /file/2.txt

    [root@node01 ~]# file /file/2.txt.bz2
    /file/2.txt.bz2: bzip2 compressed data, block size = 900k
    [root@node01 ~]#

    解压缩:

    [root@node01 ~]# bzip2 -d /file/2.txt.bz2

    xz *.xz

    压缩:

    [root@node01 ~]# xz /file/3.txt

    [root@node01 ~]# file /file/3.txt.xz
    /file/3.txt.xz: XZ compressed data

    解压缩:

    [root@node01 ~]# xz -d /file/3.txt.xz

    创建打包文件 --- tar

    创建打包文件 *.tar

    tar cf 打包文件名称 源文件

    c: create创建
    f:file文件
    

    需求:将file下的文件,打包放到/bak目录下,文件名为file01.tar
    [root@node01 ~]# tar cf /bak/file01.tar /file/

    解包

    tar xf 打包文件名称 [-C 目录名称]

    [root@node01 ~]# tar xf /bak/file01.tar

    [root@node01 ~]# tar xf /bak/file01.tar -C /tmp/

    查看包中的文件

    [root@node01 ~]# tar tvf /bak/file01.tar

    对打包文件进行压缩

    调用gzip实现压缩/解压缩

    压缩:

    tar czf 打包文件名称 源文件

    z:调用gzip 
    

    需求:将etc目录下的文件,打包且经行压缩,存放到/bak目录下,文件命名为:etc02.tar.gz
    [root@node01 ~]# tar czf /bak/etc02.tar.gz /etc/

    [root@node01 ~]# tar czf /bak/etc-$(date +%F).tar.gz /etc/

    解压缩:

    tar xzf 打包文件名称 [-C 目录名称]

    [root@node01 ~]# tar zxf /bak/etc02.tar.gz -C /tmp/

    调用bzip2实现压缩/解压缩

    压缩:

    tar cjf 打包文件名称 目录名称

    j:调用bzip2 
    

    [root@node01 ~]# tar cjf /bak/etc03.tar.bz2 /etc/

    解压缩:

    tar xjf 打包文件名称 [-C 目录名称]

    [root@node01 ~]# tar xjf /bak/etc03.tar.bz2 -C /tmp/

    调用xz实现压缩/解压缩

    压缩:

    tar cJf 打包文件名称 目录名称

    J:调用xz
    

    [root@node01 ~]# tar cJf /bak/etc04.tar.xz /etc/

    解压缩:

    tar xJf 打包文件名称 [-C 目录名称]

    [root@node01 ~]# tar xJf /bak/etc03.tar.xz -C /tmp/

    有志者,事竟成,破釜沉舟,百二秦关终属楚; 苦心人,天不负,卧薪尝胆,三千越甲可吞吴。 想到与得到中间还有两个字——做到。
  • 相关阅读:
    CodeForces 660D Number of Parallelograms
    【POJ 1082】 Calendar Game
    【POJ 2352】 Stars
    【POJ 2481】 Cows
    【POJ 1733】 Parity Game
    【NOI 2002】 银河英雄传说
    【NOI 2015】 程序自动分析
    【POJ 1704】 Georgia and Bob
    【HDU 2176】 取(m堆)石子游戏
    【SDOI 2016】 排列计数
  • 原文地址:https://www.cnblogs.com/huoxc/p/13632521.html
Copyright © 2020-2023  润新知