Linux下查看压缩文件内容的10种方法(小结)

本文介绍了一种在不预先解压缩的情况下查看归档或压缩文件内容的10种方法,包括使用Vim、tar、rar、unrar等命令,以及zip、less等工具,提供了解决日常需求的实用技巧。

通常来说,我们查看归档或压缩文件的内容,需要先进行解压缩,然后再查看,比较麻烦。今天给大家介绍 10 不同方法,能够让你轻松地在未解压缩的情况下查看归档或压缩文件的内容。

从技术上讲,查看归档或压缩文件不提前进行解压是不可能的。本文介绍的方法中会将这些压缩文件在后台一个临时目录 /tmp 中进行解压缩。重启系统后,/tmp 目录的内容将被清空。

在进一步讨论之前,这里先解释一下归档和压缩文件。

  • 归档 是将多个文件或文件夹组合成一个文件的过程。在这种情况下,生成的文件没有被压缩。
  • 压缩 是一种将多个文件或文件夹组合成一个文件并进行压缩得到的结果文件。

归档文件不是压缩文件,但压缩文件可以是归档文件。明白了这两个概念之后,我们正式介绍如何在不解压的情况下查看压缩文件内容。

1.使用 Vim 编辑器

Vim 不仅仅是编辑器,它还包含其他许多强大的功能。下面的命令将直接显示压缩归档文件的内容:

$ vim test.tar.gz复制代码

1

" tar.vim version v29

1

2

3

4

5

6

" Browsing tarfile /home/alvin/test.tar.gz

" Select a file with cursor and press ENTER

test/imag.jpg

test/file.pdf

test/song.mp3

test/

不仅如此,使用 Vim 你甚至可以直接浏览归档文件,若其中有文本文件,你还可以直接 打开它,非常方便。

如果需要打开文本文件,只需使用箭头键将光标移到文件前面,然后按 ENTER 键即可打开

2.使用 tar 命令

tar 命令不仅仅可以用于压缩/解压文件,还可以在不提取 tar 文件的情况下使用 tar -tf 命令查看压缩包内容。

1

$ tar -tf test.tar

1

2

3

4

test/

test/image.jpg

test/file.pdf

test/song.mp3

或者,使用 -v 选项查看归档文件的详细属性,例如权限、文件所有者、组、创建日期等。

1

$ tar -tvf test.tar

1

2

3

4

drwxr-xr-x alvin/users 0 2019-07-02 19:30 test/

-rw-r--r-- alvin/users 53632 2019-06-29 15:57 test/image.jpg

-rw-r--r-- alvin/users 156831 2019-06-04 12:37 test/file.pdf

-rw-r--r-- alvin/users 9702219 2019-04-25 20:35 test/song.mp3

3.使用 rar 命令

同样地,在不提取 rar 文件的情况下可以使用 rar v 命令查看压缩包内容。

1

$ rar v test.rar

1

2

3

4

5

6

7

8

9

10

11

RAR 5.60 Copyright (c) 1993-2019 Alexander Roshal 24 Jun 2019

Trial version Type 'rar -?' for help

Archive: test.rar

Details: RAR 5

Attributes Size Packed Ratio Date Time Checksum Name

----------- --------- -------- ----- ---------- ----- -------- ----

-rw-r--r-- 53632 52166 97% 2019-06-29 15:57 70260AC4 test/image.jpg

-rw-r--r-- 156831 139094 88% 2019-06-04 12:37 C66C545E test/file.pdf

-rw-r--r-- 9702219 9658527 99% 2019-04-25 20:35 DD875AC4 test/song.mp3

----------- --------- -------- ----- ---------- ----- -------- ----

9912682 9849787 99% 3

4.使用 unrar 命令

对于上面的 rar 文件,你也可以使用带有 l 参数的 unrar 命令查看 rar 文件的内容。

1

$ unrar l test.rar

1

2

3

4

5

6

7

8

9

10

UNRAR 5.60 freeware Copyright (c) 1993-2019 Alexander Roshal

Archive: test.rar

Details: RAR 5

Attributes Size Date Time Name

----------- --------- ---------- ----- ----

-rw-r--r-- 53632 2019-06-29 15:57 test/image.jpg

-rw-r--r-- 156831 2019-06-04 12:37 test/file.pdf

-rw-r--r-- 9702219 2019-04-25 20:35 test/song.mp3

----------- --------- ---------- ----- ----

9912682 3

5.使用 zip 命令

在不提取 zip 文件的情况下可以使用 zip -sf 命令查看其内容。

1

$ zip -sf test.zip

1

2

3

Archive contains:

Life advices.jpg

Total 1 entries (597219 bytes)

6.使用 unzip 命令

与 unrar 差不多,使用 -l 参数的 unzip 命令来查看 zip 文件的内容。

1

$ unzip -l test.zip

1

2

3

4

5

6

Archive: test.zip

Length Date Time Name

--------- ---------- ----- ----

597219 2019-04-09 12:48 Life advices.jpg

--------- -------

597219 1 file

7.使用 zipinfo 命令

查看 zip 文件内容,你还可以使用 zipinfo 命令。

1

$ zipinfo test.zip

1

2

3

4

Archive: test.zip

Zip file size: 584859 bytes, number of entries: 1

-rw-r--r-- 6.3 unx 597219 bx defN 18-Apr-09 12:48 Life advices.jpg

1 file, 597219 bytes uncompressed, 584693 bytes compressed: 2.1%

8.使用 zcat 命令

使用 zcat 命令查看归档/压缩文件。

1

$ zcat test.tar.gz

zcat 与 gunzip -c 命令功能相同。因此,你还可以用下面的命令:

1

$ gunzip -c test.tar.gz

9.使用 zless 命令

使用 zless 命令查看归档/压缩文件。

1

$ zless test.tar.gz

zless 类似于 less ,它可以逐页显示内容。

10.使用 less 命令

less 命令大家都可能有所了解了,它能以交互的方式查看文件内容。不仅如此,它还可以用来查看归档/压缩文件的内容:

1

$ less test.tar.gz

小结

上面简单介绍了 10 个不同的命令,可以使让你能够在不提取文件的前提下查看归档/压缩文件的内容,若你对其中某些命令感兴趣,可以自己慢慢钻研。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

Applies basic field behavior in circuit design and demonstrates how it relates to grounding and shielding requirements and techniques in circuit designThis book connects the fundamentals of electromagnetic theory to the problems of interference in all types of electronic design. The text covers power distribution in facilities, mixing of analog and digital circuitry, circuit board layout at high clock rates, and meeting radiation and susceptibility standards. The author examines the grounding and shielding requirements and techniques in circuit design and applies basic physics to circuit behavior. The sixth edition of this book has been updated with new material added throughout the chapters where appropriate. The presentation of the book has also been rearranged in order to reflect the current trends in the field.Grounding and Shielding: Circuits and Interference, Sixth Edition: Includes new material on vias and field control, capacitors as transmission lines, first energy sources, and high speed designs using boards with only two layersDemonstrates how circuit geometry controls performance from dc to gigahertzExamines the use of multi-shielded transformers in clean-power installationsProvides effective techniques for handling noise problems in analog and digital circuitsDiscusses how to use conductor geometry to improve performance, limit radiation, and reduce susceptibility to all types of hardware and systemsGrounding and Shielding: Circuits and Interference, Sixth Edition is an updated guide for circuit design engineers and technicians. It will also serve as a reference for engineers in the semiconductor device industry.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值