当前位置: 首页 > article >正文

Linux shell编程学习笔记81:zcat命令——快速查看压缩文件内容

0 引言

Linux shell编程学习笔记80:gzip命令——让文件瘦身-CSDN博客icon-default.png?t=O83Ahttps://blog.csdn.net/Purpleendurer/article/details/141862213?spm=1001.2014.3001.5501中,我们使用gzip命令可以创建压缩文件。那么,我们可以使用zcat命令来查看压缩文件的内容。

1 zcat 的功能,帮助信息,格式,选项和参数说明

1.1 zcat 的功能

在Linux中,cat命令常用于显示常规文本文件的内容.

zcat命令则是针对压缩文件的cat命令版本,全称为“concatenate for gzipped files”,主要用于显示gzip压缩文件的内容。这个命令可以说是查看压缩文件内容的捷径,因为它免去了先解压再查看的繁琐步骤。

1.2 zcat 的帮助信息


我们可以使用 zcat -help 命令获取帮助信息。

1.2.1 bash中的zcat帮助信息 

[prupleendurer @ bash ~] zcat --help
Usage: /usr/bin/zcat [OPTION]... [FILE]...
Uncompress FILEs to standard output.

  -f, --force       force; read compressed data even from a terminal
  -l, --list        list compressed file contents
  -q, --quiet       suppress all warnings
  -r, --recursive   operate recursively on directories
  -S, --suffix=SUF  use suffix SUF on compressed files
  -t, --test        test compressed file integrity
  -v, --verbose     verbose mode
      --help        display this help and exit
      --version     display version information and exit

With no FILE, or when FILE is -, read standard input.

Report bugs to <bug-gzip@gnu.org>.
[prupleendurer @ bash ~] 

1.2.2 银河麒麟(kylin)系统中的zcat帮助信息

[purpleendurer @ kylin ~] zcat --help
Usage: /bin/zcat [OPTION]... [FILE]...
Uncompress FILEs to standard output.

  -f, --force       force; read compressed data even from a terminal
  -l, --list        list compressed file contents
  -q, --quiet       suppress all warnings
  -r, --recursive   operate recursively on directories
  -S, --suffix=SUF  use suffix SUF on compressed files
  -t, --test        test compressed file integrity
  -v, --verbose     verbose mode
      --help        display this help and exit
      --version     display version information and exit

With no FILE, or when FILE is -, read standard input.

Report bugs to <bug-gzip@gnu.org>.
[purpleendurer @ kylin ~]

1.3 zcat 的命令格式

zcat [选项]... [文件]...

1.4 zcat 的选项和参数说明

1.4.1 zcat的选项

选项说明备注
-f, --force强制读取;甚至可以从终端读取压缩数据
-l, --list列出压缩文件内容与gzip相同
-q, --quiet抑制所有警告,即不显示警告信息与gzip相同
-r,--recursive对目录递归操作与gzip相同
-S, --suffix=SUF在压缩文件上使用后缀 SUF,当压缩包文件后缀不是标准压缩包后缀时使用此选项。
-t, --test测试压缩文件的完整性与gzip相同
-v, --verbose详细模式与gzip相同
--help显示帮助信息并退出与gzip相同
--version显示版本信息并退出与gzip相同

1.4.2 zcat的参数

文件:表示要查看的一个或多个压缩文件。 

2 zcat使用实例

2.1 创建演示文件

我们先使用 echo 命令和输出重定向在当前目录下创建文件f1.txt 和 f2.txt,然后使用 gzip命令对f1.txt和f2.txt 进行压缩,生成压缩文件f1.txt.gz 和 f2.txt.gz

[purpleendurer @ bash ~] echo "f1" > f1.txt
[purpleendurer @ bash ~] echo "f2" > f2.txt
[purpleendurer @ bash ~] gzip  < f1.txt > f1.txt.gz
[purpleendurer @ bash ~] gzip  < f2.txt > f2.txt.gz
[purpleendurer @ bash ~] ls
Code  f1.txt  f1.txt.gz  f2.txt  f2.txt.gz
[purpleendurer @ bash ~] 

2.2 查看压缩文件

2.2.1 zcat 文件名

例如,我们要查看目录下的所有以英文字母f开头的压缩文件 

[purpleendurer @ bash ~] zcat f*.txt.gz
f1
f2
[purpleendurer @ bash ~] zcat -iv f*.txt.gz

如果我们只指定文件名,不指定任何选项, 命令显示的信息非常有限。

2.2.2 zcat -l 文件名 : 查看压缩文件的内容

使用-l参数,我们可以看到压缩文件的内容。

例如,我们要查看目录下的所有以英文字母f开头的压缩文件的信息

[purpleendurer @ bash ~] zcat -l f*.txt.gz
         compressed        uncompressed  ratio uncompressed_name
                 23                   3 -66.7% f1.txt
                 23                   3 -66.7% f2.txt
                 46                   6 -366.7% (totals)
[purpleendurer @ bash ~] gzip -l f*.txt.gz
         compressed        uncompressed  ratio uncompressed_name
                 23                   3 -66.7% f1.txt
                 23                   3 -66.7% f2.txt
                 46                   6 -366.7% (totals)
[purpleendurer @ bash ~] 

zcat -l命令显示的信息包括4列内容,其含意分别是:

  1. compressed               :压缩后
  2. uncompressed           :压缩前
  3. ratio                            :压缩率
  4. uncompressed_name :解压缩的文件名称

可以看到,zcat -lv命令执行的结果和gzip -lv命令执行的结果是相同的。

 

可以看到,zcat -l命令执行的结果和gzip -l命令执行的结果是相同的。

2.2.3 zcat -lv 文件名:查看压缩文件的详细内容

使用-v参数,我们可以看到压缩文件更详细的信息。

例如,我们要查看目录下的所有以英文字母f开头的压缩文件的详细信息:

[purpleendurer @ bash ~] zcat -lv f*.gz
method  crc     date  time           compressed        uncompressed  ratio uncompressed_name
defla 9593802c Sep 18 23:20                  23                   3 -66.7% f1.txt
defla bebed3ef Sep 18 23:20                  23                   3 -66.7% f2.txt
                                             46                   6 -366.7% (totals)
[purpleendurer @ bash ~] gzip -lv f*.gz
method  crc     date  time           compressed        uncompressed  ratio uncompressed_name
defla 9593802c Sep 18 23:20                  23                   3 -66.7% f1.txt
defla bebed3ef Sep 18 23:20                  23                   3 -66.7% f2.txt
                                             46                   6 -366.7% (totals)
[purpleendurer @ bash ~] 

zcat -lv命令显示的信息包括8列内容,比zcat -l命令多了前面4列。这8列信息的含意分别是:

  1. method                       :压缩方法
  2. crc                              :crc校验码
  3. date                            :日期
  4. time                            :时刻
  5. compressed               :压缩后
  6. uncompressed           :压缩前
  7. ratio                            :压缩率
  8. uncompressed_name :解压缩的文件名称

可以看到,zcat -lv命令执行的结果和gzip -lv命令执行的结果是相同的。

2.3 zcat -tv 文件名:测试压缩文件完整性

使用-t参数,我们可以测试压缩文件的完整性。

例如,我们要查看目录下的所有以英文字母f开头的压缩文件的详细信息:

[purpleendurer @ bash ~] zcat -t f*.gz
[purpleendurer @ bash ~] zcat -tv f*.gz
f1.txt.gz:       OK
f2.txt.gz:       OK
[purpleendurer @ bash ~] gzip -t f*.gz
[purpleendurer @ bash ~] gzip -tv f*.gz
f1.txt.gz:       OK
f2.txt.gz:       OK
[purpleendurer @ bash ~] 

如果只使用-t选项,zcat没有显示反馈信息。

我们让-v和-t两个选项一起使用,就可以看到测试的结果。

我们同样看到,zcat -tv命令执行的结果和gzip -tv命令执行的结果是相同的。

2.4 zcat -ltv 文件名 = zcat -lv 文件名

如果我们同时使用ltv三个选项,会看到什么结果呢?

我们以查看目录下的所有以英文字母f开头的压缩文件为例来看看:

[purpleendurer @ bash ~] zcat -ltv f*.gz
method  crc     date  time           compressed        uncompressed  ratio uncompressed_name
defla 9593802c Sep 18 23:20                  23                   3 -66.7% f1.txt
defla bebed3ef Sep 18 23:20                  23                   3 -66.7% f2.txt
                                             46                   6 -366.7% (totals)
[purpleendurer @ bash ~] gzip -ltv f*.gz
method  crc     date  time           compressed        uncompressed  ratio uncompressed_name
defla 9593802c Sep 18 23:20                  23                   3 -66.7% f1.txt
defla bebed3ef Sep 18 23:20                  23                   3 -66.7% f2.txt
                                             46                   6 -366.7% (totals)
[purpleendurer @ bash ~] 

 

 2.5 zcat -V:查看版本信息

[purpleendurer @ bash ~] zcat -V
gzip 1.5
Copyright (C) 2007, 2010, 2011 Free Software Foundation, Inc.
Copyright (C) 1993 Jean-loup Gailly.
This is free software.  You may redistribute copies of it under the terms of
the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
There is NO WARRANTY, to the extent permitted by law.

Written by Jean-loup Gailly.
[purpleendurer @ bash ~] gzip -V
gzip 1.5
Copyright (C) 2007, 2010, 2011 Free Software Foundation, Inc.
Copyright (C) 1993 Jean-loup Gailly.
This is free software.  You may redistribute copies of it under the terms of
the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
There is NO WARRANTY, to the extent permitted by law.

Written by Jean-loup Gailly.
[purpleendurer @ bash ~] 

zcat和gzip是亲如一家呀 


http://www.kler.cn/news/310117.html

相关文章:

  • 函数题 6-10 阶乘计算升级版【PAT】
  • IOS 25 实现歌单详情(UITableView)列表 ②
  • 即插即用 | YOLOv8热力图可视化方法详解
  • MySQL的(DDL、DCL、DQL、DML)语言学习
  • 7.7opencv中(基于C++) 翻转图像
  • 完全解决git clone超时和git子模块无法下载问题
  • CSS学习路线
  • 11 vue3之插槽全家桶
  • 【JavaEE】多线程编程引入——认识Thread类
  • mysql怎样优化count(*) from 表名 where …… or ……这种慢sql
  • c++基础入门三
  • Java Web开发中处理Response返回值的技巧与实践
  • 1×1卷积核【super star 卷积核】
  • 【数据结构-线段树】【差分】力扣732. 我的日程安排表 III
  • 基于PHP的丽江旅游管理系统
  • VMware ESXi 7.0U3q macOS Unlocker 集成驱动版更新 OEM BIOS 2.7 支持 Windows Server 2025
  • STM32快速复习(十二)FLASH闪存的读写
  • [Meachines] [Medium] Bart Server Monitor+Internal Chat+UA投毒+Winlogon用户密码泄露权限提升
  • MySQL高阶1777-每家商店的产品价格
  • 文心智能体 恐怖类游戏
  • 一.Oracle每日运维操作
  • bug | pycharm社区版无sciview解决办法
  • JVM 调优篇7 调优案例1-堆空间的优化解决
  • Holynix: v1
  • 基于SSM的在线家用电器销售系统
  • 【ARM】Trustzone和安全架构
  • [SDX35+WCN6856]SDX35 + WCN6856 WiFi导致系统crash问题分析及解决方案
  • (娱乐)魔改浏览器-任务栏图标右上角加提示徽章
  • 线性链条件随机场(Linear Chain Conditional Random Field)-有监督学习方法、概率模型、生成模型、对数线性模型、参数化模型
  • 力扣(LeetCode)每日一题 1184. 公交站间的距离