zoukankan      html  css  js  c++  java
  • Linux gzip压缩/解压 *.gz文件详解

    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

    示例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,解压文件
    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,压缩的时候,显示压缩率
    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,压缩过程中,保留原文件
    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
    ======================================

    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 
     

    正因为当初对未来做了太多的憧憬,所以对现在的自己尤其失望。生命中曾经有过的所有灿烂,终究都需要用寂寞来偿还。
  • 相关阅读:
    什么是首次适应算法,该算法的特点是什么?
    用上、下界防护方法是如何实现界地址保护?在硬件上需要什么支持?
    什么是存储保护?
    什么是静态地址重定位,它需要什么支持?什么是动态地址重定位,他需要什么支持?静态地址重定位与动态地址重定位有什么区别?
    什么是逻辑地址,什么是物理地址,为什么要进行二者的转换工作?
    三个进程共享四个同类资源,这些资源的分配与释放只能一次一个。已知每一个进程最多需要两个资源,试问,该系统会发生死锁吗?为什么?
    试举出一种一种避免死锁的发生的方法,并说明为什么能避免死锁的发生?
    产生死锁的原因是什么?产生死锁的必要条件是什么?
    什么是死锁,试举例说明?
    说出两种一笔调度的算法,并说出这两种移臂调度算法的定义。
  • 原文地址:https://www.cnblogs.com/candlia/p/11919959.html
Copyright © 2011-2022 走看看