• gzip


    压缩和解压缩文件

    gzip [options] [file-list]

    gunzip [options] [file-list]

    zcat [file-list]

    gzip程序用来压缩文件,gunzip程序用来还原gzip压缩的文件,zcat程序用来显示gzip压缩的文件

    压缩后会删除原始文件,压缩过的文件后缀为.gz

    参数

    file-list 为要压缩或解压缩的一个或者多个文件的路径名列表。如果在file-list中存在目录但没有选项-r,则gzip/gunzip会报告错误消息并忽略该目录

    使用-r选项,gzip/gunzip会递归地压缩/解压缩目录层次结构中的文件

    选项

    -c                 将压缩或解压缩的结果写到标准输出,而不是写到文件

    -d                 解压缩用gzip压缩的文件。该选项用于gzip,与gunzip等价

    -f                  压缩/解压缩时强制覆盖已存在的文件

    -l                  对于在file-list中要压缩的每个文件,显示压缩和解压缩后文件的大小、压缩比和压缩前的文件名

                        -v可获得其他信息

    -n                 在压缩速度和压缩量间进行权衡。n为从1~9的数字。第1级为最快压缩,但压缩量最小;第9级的压缩速度最慢,但压缩量最大。

                        默认级别为6,--fast和--best分别等价于-1和-9

    -q                 禁止显示警告信息

    -r                  递归压缩/解压缩file-list中的文件

    -t                  验证压缩文件的完整性。如果文件完整则不显示任何信息

    -v                 显示文件名、压缩后的文件名和每个被处理文件的压缩量

    示例

    gzip

    siu@Darling ~/work $ ls
    a  b  c  dir
    siu@Darling ~/work $ gzip a
    siu@Darling ~/work $ ls
    a.gz  b  c  dir
    siu@Darling ~/work $ 

    压缩文件,并删除原始文件

    gzip -v

    siu@Darling ~/work $ gzip -v b
    b:     26.4% -- replaced with b.gz
    siu@Darling ~/work $ ls
    a.gz  b.gz  c  dir

    压缩文件,并显示压缩信息

    gunzip

    siu@Darling ~/work $ gunzip a.gz 
    siu@Darling ~/work $ ls
    a  b.gz  c  dir

    解压文件,gunzip == gzip -d

    zcat

    siu@Darling ~/work $ zcat b.gz 
    Picture perfect memories scattered all around the floor
    Reaching for the phone 'cause I can't fight it anymore
    And I wonder if I ever cross your mind
    For me it happens all the time

    不解压而显示压缩文件的内容

    gunzip -c

    siu@Darling ~/work $ gunzip -c b.gz 
    Picture perfect memories scattered all around the floor
    Reaching for the phone 'cause I can't fight it anymore
    And I wonder if I ever cross your mind
    For me it happens all the time

    解压文件到标准输出,也就是一解压就输出内容到屏幕,不改动文件

    gunzip -l

    siu@Darling ~/work $ gunzip -l b.gz 
             compressed        uncompressed  ratio uncompressed_name
                    154                 182  26.4% b
    siu@Darling ~/work $ ls
    a  b.gz  c  dir

    显示压缩和解压缩的信息,但并不执行解压缩

    gzip -9 -r

    复制代码
    siu@Darling ~/work $ gzip -9 -r dir
    siu@Darling ~/work $ ls
    a  b.gz  c  dir
    siu@Darling ~/work $ ls -l dir
    总用量 12
    -rw-r--r-- 1 siu siu 154  1月 12 16:22 a.gz
    -rw-r--r-- 1 siu siu 154  1月 12 16:22 b.gz
    -rw-r--r-- 1 siu siu 154  1月 12 16:22 c.gz
    复制代码

    用压缩量最大的方式递归压缩目录中的文件

    Tips

    gzip对文本文件压缩效果较明显,二进制文件或大文件推荐使用bzip2压缩

  • 相关阅读:
    Solr 删除数据的几种方式
    velocity 随笔
    LOG4J.PROPERTIES配置详解(转载)
    转 如何使用velocity模板引擎开发网站
    通过pinyin4j将汉字转换为全拼 和 拼音首字母
    去除数组中的重复数据
    java 转义字符
    多重背包(学习笔记)
    Team Queue
    [HAOI2008]糖果传递
  • 原文地址:https://www.cnblogs.com/qzqdy/p/8204899.html
Copyright © 2020-2023  润新知