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

  • 12
    点赞
  • 49
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值