• gzip的使用


    转自:原文链接:https://blog.csdn.net/londa/article/details/108185354

    【1】gzip 一般形式

    gzip 是linux中常见的压缩/解压工具,最常见的使用对象是*.gz格式的文件,这里简单介绍下它最常见的用法,

      GZIP(1) General Commands Manual GZIP(1)

    NAME
      gzip, gunzip, zcat - compress or expand files

    SYNOPSIS
      gzip [ -acdfhklLnNrtvV19 ] [--rsyncable] [-S suffix] [ name ... ]
      gunzip [ -acfhklLnNrtvV ] [-S suffix] [ name ... ]
      zcat [ -fhLV ] [ name ... ]

    OPTIONS

    -c --stdout --to-stdout 结果写到标准输出,原文件保持不变
    -d --decompress --uncompress 解压
    -k --keep 压缩或者解压过程中,保留原文件
    -r --recursive
    -t --test 检查压缩文件的完整性
    -v --verbose 显示每个文件的名子和压缩率
    -# --fast --best 取值从-1(最快)到-9(最好),默认是-6

    【2】案例

    示例1,压缩文件

    原文件名为file1.txt,压缩后原文件消失,压缩后文件名为file1.txt.gz

    root@ubuntu:/tmp# ls -l file1.*
    -rw-r--r-- 1 root root 12383865 Aug 21 08:08 file1.txt
    root@ubuntu:/tmp# gzip file1.txt
    root@ubuntu:/tmp# ls -l file1.*
    -rw-r--r-- 1 root root 134416 Aug 21 08:08 file1.txt.gz

    示例2,-d 解压文件

    root@ubuntu:/tmp# gzip -d file1.txt.gz
    root@ubuntu:/tmp# ls -lh file1.*
    -rw-r--r-- 1 root root 12M Aug 21 08:08 file1.txt

    示例3,-v 压缩的时候,显示压缩率

    root@ubuntu:/tmp# gzip -v file1.txt
    file1.txt: 98.9% -- replaced with file1.txt.gz

    示例4,一条命令压缩多个文件,压缩之后,是各自分开的:

    root@ubuntu:/tmp# gzip file1.txt file2.txt
    root@ubuntu:/tmp# ls -l
    total 1348
    -rw-r--r-- 1 root root 134416 Aug 21 08:08 file1.txt.gz
    -rw-r--r-- 1 root root 392 Aug 21 08:15 file2.txt.gz

    示例5,-k 压缩过程中,保留原文件

    root@ubuntu:/tmp# gzip -k file1.txt
    root@ubuntu:/tmp# ls file1.*
    file1.txt file1.txt.gz

    示例6,压缩到标准输出中

    可以连接两个文件
    root@ubuntu:/tmp# cat file1.txt file2.txt | gzip > foo.gz
    或者
    root@ubuntu:/tmp# gzip -c file1.txt file2.txt > foo.gz
    ======================================

    【3】各个命令的配合使用情况

    gzip

    压缩后的格式为:*.gz

    这种压缩方式不能保存原文件;且不能压缩目录

    命令举例:
    #压缩
    [root@localhost tmp]# gzip buodo
    [root@localhost tmp]# ls
    buodo.gz
    #解压
    [root@localhost tmp]# gunzip buodo.gz
    [root@localhost tmp]# ls
    buodo

    tar

    命令选项:
    -z(gzip) 用gzip来压缩/解压缩文件
    -j(bzip2) 用bzip2来压缩/解压缩文件
    -v(verbose) 详细报告tar处理的文件信息
    -c(create) 创建新的档案文件
    -x(extract) 解压缩文件或目录
    -f(file) 使用档案文件或设备,这个选项通常是必选的。

    命令举例:
    #压缩
    [root@localhost tmp]# tar -zvcf buodo.tar.gz buodo
    [root@localhost tmp]# tar -jvcf buodo.tar.bz2 buodo

    #解压
    [root@localhost tmp]# tar -zvxf buodo.tar.gz
    [root@localhost tmp]# tar -jvxf buodo.tar.bz2

    zip

    与gzip相比:1)可以压缩目录; 2)可以保留原文件;

    选项:

    -r(recursive) 递归压缩目录内的所有文件和目录

    命令举例:
    #压缩和解压文件
    [root@localhost tmp]# zip boduo.zip boduo
    [root@localhost tmp]# unzip boduo.zip

    #压缩和解压目录
    [root@localhost tmp]# zip -r Demo.zip Demo
    adding: Demo/ (stored 0%)
    adding: Demo/Test2/ (stored 0%)
    adding: Demo/Test1/ (stored 0%)
    adding: Demo/Test1/test4 (stored 0%)
    adding: Demo/test3 (stored 0%)
    [root@localhost tmp]# unzip Demo.zip
    Archive: Demo.zip
    creating: Demo/
    creating: Demo/Test2/
    creating: Demo/Test1/
    extracting: Demo/Test1/test4
    extracting: Demo/test3

    bzip2

    压缩后的格式:.bz2
    参数
    -k 产生压缩文件后保留原文件

    命令举例
    #压缩
    [root@localhost tmp]# bzip2 boduo
    [root@localhost tmp]# bzip2 -k boduo

    #解压
    [root@localhost tmp]# bunzip2 boduo.bz2
    ————————————————
    版权声明:本文为CSDN博主「AllenLeungX」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/londa/article/details/108185354

  • 相关阅读:
    Ubuntu 14.04 配置iptables防火墙
    转 微软Sysinternals Suite工具13年12月版下载
    转详解Zoosk千万用户实时通信背后的开源技术
    Where is Silverlight now?
    A glance at C# vNext
    silverlight 进行本地串口调用的一种可行的解决方法 之silverlight端代码
    silverlight 进行本地串口调用的一种可行的解决方法
    silverlight 中javascript 代码与托管代码的互调用 以及一些思考
    使用cglib动态创建javabean
    数据库同步核心代码
  • 原文地址:https://www.cnblogs.com/gered/p/15871317.html
Copyright © 2020-2023  润新知