Results 1 to 1 of 1

Thread: Linux中使用gzip来压缩/解压 *.gz文件

  1. #1
    Join Date
    2013-01-05
    Posts
    1

    Default Linux中使用gzip来压缩/解压 *.gz文件

    摘要:gzip是linux中常见的压缩/解压工具,最常见的使用对象是*.gz格式的文件,这里简单介绍下它最常见的用法,GZIP(1)GeneralCommandsManualGZIP(1)NAME gzip,gunzip,zcat-compressorexpandfilesSYNOPSIS gzip[-acdfhklLnNrtvV19][--rsyncable][-Ssuffix][name...] &n
    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
    aliyunzixun@xxx.com:/tmp# ls -l file1.*
    -rw-r--r-- 1 root root 12383865 Aug 21 08:08 file1.txt
    aliyunzixun@xxx.com:/tmp# gzip file1.txt
    aliyunzixun@xxx.com:/tmp# ls -l file1.*
    -rw-r--r-- 1 root root 134416 Aug 21 08:08 file1.txt.gz

    示例2,解压文件
    aliyunzixun@xxx.com:/tmp# gzip -d file1.txt.gz
    aliyunzixun@xxx.com:/tmp# ls -lh file1.*
    -rw-r--r-- 1 root root 12M Aug 21 08:08 file1.txt

    示例3,压缩的时候,显示压缩率
    aliyunzixun@xxx.com:/tmp# gzip -v file1.txt
    file1.txt: 98.9% -- replaced with file1.txt.gz

    示例4,一条命令压缩多个文件,压缩之后,是各自分开的:
    aliyunzixun@xxx.com:/tmp# gzip file1.txt file2.txt
    aliyunzixun@xxx.com:/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,压缩过程中,保留原文件
    aliyunzixun@xxx.com:/tmp# gzip -k file1.txt
    aliyunzixun@xxx.com:/tmp# ls file1.*
    file1.txt file1.txt.gz

    示例6,压缩到标准输出中
    可以连接两个文件
    aliyunzixun@xxx.com:/tmp# cat file1.txt file2.txt | gzip > foo.gz
    或者
    aliyunzixun@xxx.com:/tmp# gzip -c file1.txt file2.txt > foo.gz
    Last edited by Muldoon; 2018-10-30 at 10:16 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 2017-08-03, 10:46 AM
  2. Linux下的压缩解压缩命令详解
    By Alamo in forum Linux
    Replies: 0
    Last Post: 2016-09-17, 03:03 PM
  3. Replies: 0
    Last Post: 2016-06-09, 10:39 PM
  4. 在linux中如何终止指令的运行?
    By Raiden in forum Linux
    Replies: 0
    Last Post: 2015-01-19, 05:01 AM
  5. linux下创建文件夹
    By topvip in forum 代码交流
    Replies: 0
    Last Post: 2012-03-02, 04:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •