查看压缩及归档文件内容


  • 首先要明确的是,压缩文件不解压缩进行查看 是不可能的,所以下文中方式,包括 windows 上双击查看都是将文件解压缩放到临时目录,然后展示其中的内容。

查看压缩文件

unzip / zip /zipinfo

  • unzip 是 下边 vim 查看使用的底层命令;
$ unzip -l test.zip
---

Archive:  test.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  2023-09-22 20:12   a.txt
        0  2023-09-22 20:12   b.txt
---------                     -------
        0                     2 files
        
$ unzip -l math-game.jar
Archive:  math-game.jar
  Length      Date    Time    Name
---------  ---------- -----   ----
      233  2020-09-27 15:10   META-INF/MANIFEST.MF
        0  2020-09-27 15:10   META-INF/
        0  2020-09-27 15:10   demo/
        0  2020-09-27 15:10   META-INF/maven/
        0  2020-09-27 15:10   META-INF/maven/com.taobao.arthas/
        0  2020-09-27 15:10   META-INF/maven/com.taobao.arthas/math-game/
      485  2020-09-27 15:10   arthas-git.properties
     3128  2020-09-27 15:10   demo/MathGame.class
     3463  2020-09-27 15:10   META-INF/maven/com.taobao.arthas/math-game/pom.xml
       61  2020-09-27 15:10   META-INF/maven/com.taobao.arthas/math-game/pom.properties      

$ zipinfo math-game.jar

---
Archive:  math-game.jar
Zip file size: 4486 bytes, number of entries: 10
-rw-r--r--  2.0 unx      233 b- defN 20-Sep-27 15:10 META-INF/MANIFEST.MF
drwxr-xr-x  2.0 unx        0 b- stor 20-Sep-27 15:10 META-INF/
drwxr-xr-x  2.0 unx        0 b- stor 20-Sep-27 15:10 demo/
drwxr-xr-x  2.0 unx        0 b- stor 20-Sep-27 15:10 META-INF/maven/
drwxr-xr-x  2.0 unx        0 b- stor 20-Sep-27 15:10 META-INF/maven/com.taobao.arthas/
drwxr-xr-x  2.0 unx        0 b- stor 20-Sep-27 15:10 META-INF/maven/com.taobao.arthas/math-game/
-rw-r--r--  2.0 unx      485 b- defN 20-Sep-27 15:10 arthas-git.properties
-rw-r--r--  2.0 unx     3128 b- defN 20-Sep-27 15:10 demo/MathGame.class
-rw-r--r--  2.0 unx     3463 b- defN 20-Sep-27 15:10 META-INF/maven/com.taobao.arthas/math-game/pom.xml
-rw-r--r--  2.0 unx       61 b- defN 20-Sep-27 15:10 META-INF/maven/com.taobao.arthas/math-game/pom.properties
10 files, 7370 bytes uncompressed, 3160 bytes compressed:  57.1%
  • zip -sf test.zip
 -sf
       --show-files
              Show  the files that would be operated on, then exit.  For instance, if creating a new archive, this
              will list the files that would be added.  If the option is negated, -sf-, output only to an open log
              file.  Screen display is not recommended for large lists.


---
$zip -sf test.zip
---
Archive contains:
  a.txt
  b.txt
Total 2 entries (0 bytes)

vim / less

  • 没有安装 unzip时,使用 vim 打开压缩包会提示: ***error*** (zip#Browse) unzip not available on your system
  • sudo apt -y install zip
  • 另外 vim 和 less 还可以查看jar 文件
$ vim test.zip
---
" zip.vim version v28
" Browsing zipfile /mnt/d/com_lib/test.zip
" Select a file with cursor and press ENTER

a.txt
b.txt
---

$ less test.zip
----
Archive:  test.zip
 Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
--------  ------  ------- ---- ---------- ----- --------  ----
       0  Stored        0   0% 2023-09-22 20:12 00000000  a.txt
       0  Stored        0   0% 2023-09-22 20:12 00000000  b.txt
--------          -------  ---                            -------
       0                0   0%                            2 files
test.zip (END)

$ vim math-game.jar
----
" zip.vim version v28
" Browsing zipfile /mnt/d/com_lib/math-game.jar
" Select a file with cursor and press ENTER

META-INF/MANIFEST.MF
META-INF/
demo/
META-INF/maven/
META-INF/maven/com.taobao.arthas/
META-INF/maven/com.taobao.arthas/math-game/
arthas-git.properties
demo/MathGame.class
META-INF/maven/com.taobao.arthas/math-game/pom.xml
META-INF/maven/com.taobao.arthas/math-game/pom.properties
~                                                            

查看归档文件

tar

  • tar 能查看归档文件,如果是仅压缩文件是无法查看的
$ tar -tvf test.zip
---

tar: This does not look like a tar archive
tar: Exiting with failure status due to previous errors

---

$ tar -tvf test.tar
-rwxrwxrwx qww/qww           0 2023-09-22 20:12 a.txt
-rwxrwxrwx qww/qww           0 2023-09-22 20:12 b.txt

zcat 查看 tar.gz 除了上边的命令还可用使用以zcat

  • 但是它的输出格式非常迷惑
$ zcat  test.tar.gz
a.txt                                                                                               0000777 0001750 0001750 00000000000 14503302306 010246  0                                                      ustar   qww                             qww                                                                                                                                                               b.txt                                                                                               0000777 0001750 0001750 00000000000 14503302306 010247  0                                                      ustar   qww                             qww         

---
$ tar -tvf test.tar.gz
-rwxrwxrwx qww/qww           0 2023-09-22 20:12 a.txt
-rwxrwxrwx qww/qww           0 2023-09-22 20:12 b.txt
  • 10
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值