zoukankan      html  css  js  c++  java
  • 压缩打包介绍 gzip压缩工具 bzip2压缩工具 xz压缩工具

    Linux下最常见的压缩文件通常是.tar.gz格式。

    .gz:表示有gzip压缩工具压缩的文件。

    .bz2:表示由bzip2压缩工具压缩的文件。

    .tar:表示由tar打包程序打包的文件(tar并没有压缩功能,只是把目录合并成一个文件)。

    .tar.gz:先由tar打包,然后再由gzip压缩。

    .tar.bz2:先由tar打包,然后再由bzip2压缩。

    .tar.xz:先由tar打包,然后再xz压缩。

    gzip压缩工具

    gzip [-d#] filename,其中#为1-9的数字。

    -d:在解压缩时使用。

    -#:表示压缩等级,1最差,9最差,6为默认。

    [root@lizhipeng01 ~]# mkdir /tmp/8
    [root@lizhipeng01 ~]# cd /tmp/8
    [root@lizhipeng01 8]# mkdir test
    [root@lizhipeng01 8]# mv /tmp/1.txt test
    [root@lizhipeng01 8]# cd test
    [root@lizhipeng01 test]# ls
    1.txt
    [root@lizhipeng01 test]# gzip 1.txt
    [root@lizhipeng01 test]# ls
    1.txt.gz
    [root@lizhipeng01 test]#

    gzip后面直接跟文件名,表示在当前目录下压缩该文件,原文件消失。

    [root@lizhipeng01 test]# gzip -d 1.txt.gz
    [root@lizhipeng01 test]# ls
    1.txt

    gzip -d 后面跟压缩文件表示解压缩文件。gzip不支持压缩目录。

    [root@lizhipeng01 test]# cd ..       进入上一级目录
    [root@lizhipeng01 8]# pwd            打印当前路径
    /tmp/8
    [root@lizhipeng01 8]# ls
    test

    [root@lizhipeng01 test]# gzip -c 1.txt > /tmp/1.txt.gz     压缩1.txt时,不希望1.txt消失
    [root@lizhipeng01 test]# ls
    1.txt
    [root@lizhipeng01 test]# ls /tmp/1.txt.gz
    /tmp/1.txt.gz

    [root@lizhipeng01 test]# file !$
    file /tmp/1.txt.gz
    /tmp/1.txt.gz: gzip compressed data, was "1.txt", from Unix, last modified: Tue Jan 2 03:42:12 2018

    [root@lizhipeng01 test]# gzip -d -c /tmp/8/test/1.txt.gz > /tmp/8/test/2.txt
    [root@lizhipeng01 test]# ls
    1.txt.gz 2.txt
    [root@lizhipeng01 test]# gzip -d /tmp/8/test/1.txt.gz > /tmp/8/test/2.txt
    [root@lizhipeng01 test]# ls
    1.txt 2.txt


    [root@lizhipeng01 8]# gzip test      压缩test目录
    gzip: test is a directory -- ignored
    [root@lizhipeng01 8]# ls test
    1.txt

    bzip2压缩工具

    bzip2 [-dz] filename ,-z表示压缩,-d表示解压缩。压缩级别1-9,默认级别9。

    yum install -y bzip2

    [root@lizhipeng01 8]# cd test
    [root@lizhipeng01 test]# bzip2 1.txt
    [root@lizhipeng01 test]# ls
    1.txt.bz2
    [root@lizhipeng01 test]# bzip2 -d 1.txt.bz2
    [root@lizhipeng01 test]# ls
    1.txt
    [root@lizhipeng01 test]# bzip2 -z 1.txt
    [root@lizhipeng01 test]# ls
    1.txt.bz2

    bzip2同样不能压缩目录

    [root@lizhipeng01 test]# cd ..
    [root@lizhipeng01 8]# bzip2 test
    bzip2: Input file test is a directory.

    补充

    [root@lizhipeng01 test]# ls
    1.txt 2.txt
    [root@lizhipeng01 test]# du -sh 1.txt
    28K 1.txt
    [root@lizhipeng01 test]# bzip2 1.txt
    [root@lizhipeng01 test]# ls
    1.txt.bz2 2.txt
    [root@lizhipeng01 test]# bzip2 -d -c 1.txt.bz2 > /tmp/8/test/3.txt
    [root@lizhipeng01 test]# ls
    1.txt.bz2 2.txt 3.txt
    [root@lizhipeng01 test]# bzip2 -d 1.txt.bz2 > /tmp/8/test/3.txt     去除c,1.txt.bz2不存在了
    [root@lizhipeng01 test]# ls
    1.txt 2.txt 3.txt

    xz压缩工具

    xz [-dz] filename。-z压缩,-d解压缩。

    [root@lizhipeng01 test]# cd ..
    [root@lizhipeng01 8]# bzip2 test
    bzip2: Input file test is a directory.
    [root@lizhipeng01 8]# cd test
    [root@lizhipeng01 test]# ls
    1.txt.bz2
    [root@lizhipeng01 test]# bzip2 -d 1.txt.bz2
    [root@lizhipeng01 test]# ls
    1.txt
    [root@lizhipeng01 test]# xz 1.txt
    [root@lizhipeng01 test]# ls
    1.txt.xz
    [root@lizhipeng01 test]# xz -d 1.txt.zx
    xz: 1.txt.zx: 没有那个文件或目录
    [root@lizhipeng01 test]# xz -d 1.txt.xz
    [root@lizhipeng01 test]# ls
    1.txt
    [root@lizhipeng01 test]# xz -z 1.txt
    [root@lizhipeng01 test]# ls
    1.txt.xz

    xz同样不能压缩目录

    [root@lizhipeng01 test]# cd ..
    [root@lizhipeng01 8]# xz test
    xz: test: Is a directory, skipping

  • 相关阅读:
    golang学习 ---并发获取多个URL
    MySQL的my.cnf文件(解决5.7.18下没有my-default.cnf)
    Python ElasticSearch API
    linux 输出重定向 何时会写文件
    Linux top命令的用法详细详解
    mysql 5.7.13 安装配置方法(linux)-后期部分运维
    linux下各目录的作用
    MySQL 获得当前日期时间 函数
    mysql导入大批量数据出现MySQL server has gone away的解决方法
    python之MySQL学习——防止SQL注入
  • 原文地址:https://www.cnblogs.com/sisul/p/8186412.html
Copyright © 2011-2022 走看看