【Linux】Linux上如何在不解压的情况下查看压缩包中文件列表

# tar  --help   | grep   list

  -t, --list                 list the contents of an archive

# tar -cf  CentOS.tar  CentOS/

# tar  -tvf CentOS.tar
drwxr-xr-x root/root         0 2023-07-04 14:38 CentOS/
-rw-r--r-- root/root       703 2022-08-05 01:56 CentOS/sha256sum.txt
-rw-r--r-- root/root      1563 2022-08-05 01:58 CentOS/sha256sum.txt.asc

命令 tar -tvf CentOS.tar 的详细解读如下:

  • tar: 用于创建、查看和提取归档文件的命令。
  • -t: 选项表示查看压缩包中的文件列表而不进行提取或解压缩操作。
  • -v: 选项表示以详细模式运行tar命令,输出操作的详细信息。
  • -f CentOS.tar: 指定要处理的归档文件为CentOS.tar

因此,该命令的作用是以详细模式查看.tar文件CentOS.tar中的文件列表。
命令的输出会显示压缩包中的每个文件的相关信息,包括文件名、权限、所有者、大小和修改日期等。
请注意,由于没有使用压缩选项(如-z),所以这里假设CentOS.tar是一个未压缩的.tar文件。

# tar -zvtf   yum.tar.gz

drwxr-xr-x root/root         0 2023-10-18 21:28 yum/
-rw-r--r-- root/root     16416 2023-10-18 21:27 yum/crontabs-1.11-21.ky10.noarch.rpm
-rw-r--r-- root/root     21432 2023-10-18 21:27 yum/ima-evm-utils-libs-1.3.1-6.ky10.x86_64.rpm
-rw-r--r-- root/root     82044 2023-10-18 21:27 yum/crypto-policies-20200619-1.git781bbd4.ky10.noarch.rpm
-rw-r--r-- root/root     88584 2023-10-18 21:27 yum/zlib-1.2.11-22.ky10.x86_64.rpm
-rw-r--r-- root/root    339964 2023-10-18 21:27 yum/p11-kit-0.23.20-4.ky10.x86_64.rpm
-rw-r--r-- root/root    124756 2023-10-18 21:27 yum/p11-kit-trust-0.23.20-4.ky10.x86_64.rpm
-rw-r--r-- root/root   1555964 2023-10-18 21:27 yum/mpfr-4.1.0-1.ky10.x86_64.rpm
-rw-r--r-- root/root     84820 2023-10-18 21:27 yum/libtirpc-1.2.6-2.p02.ky10.x86_64.rpm
-rw-r--r-- root/root    398192 2023-10-18 21:27 yum/findutils-4.7.0-5.p01.ky10.x86_64.rpm
drwxr-xr-x root/root         0 2023-10-18 21:28 yum/repodata/
-rw-r--r-- root/root     99296 2023-10-18 21:28 yum/repodata/5e50c9e274bff71e2b0e4bc2c59628eb7c839c4701805b02a30e718965dd0d7c-primary.xml.gz
-rw-r--r-- root/root    159419 2023-10-18 21:28 yum/repodata/eb3bfe4dd5dd7e0849414d40bb5059019336e5b70e066f88621061499064b7bf-filelists.xml.gz
-rw-r--r-- root/root     48082 2023-10-18 21:28 yum/repodata/9695d2937d874d88e59d0058aaa34cc94a2e501b12433602e5aec412500c2bed-other.xml.gz
-rw-r--r-- root/root    194958 2023-10-18 21:28 yum/repodata/6e860921c225c3a8e2814a50c1877c394239a51329d47581d179963fcf5efccf-primary.sqlite.bz2
-rw-r--r-- root/root    170745 2023-10-18 21:28 yum/repodata/e51e63f48b6bfff282e8e425d117acc46ef71acd478c77040f3ed6e8d9ba4726-filelists.sqlite.bz2
-rw-r--r-- root/root     58517 2023-10-18 21:28 yum/repodata/adcfa00ec426b384c5fe92e99b33db13a92da8ca3f605c2e31d90bdba1b5e0c2-other.sqlite.bz2
-rw-r--r-- root/root      3094 2023-10-18 21:28 yum/repodata/repomd.xml

命令 tar -zvtf yum.tar.gz 的详细解读如下:

  • tar: 用于创建、查看和提取归档文件的命令。
  • -z: 选项表示使用gzip来压缩或解压缩文件。在这里,它告诉tar命令使用gzip来解压缩.tar.gz文件。
  • -v: 选项表示以详细模式运行tar命令,输出操作的详细信息。
  • -t: 选项表示查看压缩包中的文件列表而不进行提取或解压缩操作。
  • -f yum.tar.gz: 指定要处理的归档文件为yum.tar.gz

因此,该命令的作用是以详细模式查看.tar.gz文件yum.tar.gz中的文件列表。
命令的输出会显示压缩包中的每个文件的相关信息,包括文件名、权限、所有者、大小和修改日期等。

# zip  --help

Copyright (c) 1990-2008 Info-ZIP - Type 'zip "-L"' for software license.
Zip 3.0 (July 5th 2008). Usage:
zip [-options] [-b path] [-t mmddyyyy] [-n suffixes] [zipfile list] [-xi list]
  The default action is to add or replace zipfile entries from list, which
  can include the special name - to compress standard input.
  If zipfile and list are omitted, zip compresses stdin to stdout.
  -f   freshen: only changed files  -u   update: only changed or new files
  -d   delete entries in zipfile    -m   move into zipfile (delete OS files)
  -r   recurse into directories     -j   junk (don't record) directory names
  -0   store only                   -l   convert LF to CR LF (-ll CR LF to LF)
  -1   compress faster              -9   compress better
  -q   quiet operation              -v   verbose operation/print version info
  -c   add one-line comments        -z   add zipfile comment
  -@   read names from stdin        -o   make zipfile as old as latest entry
  -x   exclude the following names  -i   include only the following names
  -F   fix zipfile (-FF try harder) -D   do not add directory entries
  -A   adjust self-extracting exe   -J   junk zipfile prefix (unzipsfx)
  -T   test zipfile integrity       -X   eXclude eXtra file attributes
  -y   store symbolic links as the link instead of the referenced file
  -e   encrypt                      -n   don't compress these suffixes
  -h2  show more help

# zip   -r   openssh-7.4p1.zip  openssh-7.4p1

  adding: openssh-7.4p1/ (stored 0%)
  adding: openssh-7.4p1/openssh-7.4p1-23.el7_9.x86_64.rpm (deflated 10%)
  adding: openssh-7.4p1/openssh-clients-7.4p1-23.el7_9.x86_64.rpm (deflated 8%)
  adding: openssh-7.4p1/openssh-server-7.4p1-23.el7_9.x86_64.rpm (deflated 11%)

命令 zip -r openssh-7.4p1.zip openssh-7.4p1 的详细解读如下:

  • zip: 用于创建和管理zip格式的压缩文件的命令。
  • -r: 选项表示递归地压缩目录及其子目录中的所有文件。
  • openssh-7.4p1.zip: 指定要创建的压缩文件名为openssh-7.4p1.zip
  • openssh-7.4p1: 指定要压缩的目录或文件为openssh-7.4p1

因此,该命令的作用是将目录openssh-7.4p1(包括其子目录中的所有文件)递归地压缩到名为openssh-7.4p1.zip的压缩文件中。
压缩文件将包含openssh-7.4p1目录下的所有文件和子目录,保持原始目录结构。

# unzip openssh-7.4p1.zip  -d test/

Archive:  openssh-7.4p1.zip
   creating: test/openssh-7.4p1/
  inflating: test/openssh-7.4p1/openssh-7.4p1-23.el7_9.x86_64.rpm
  inflating: test/openssh-7.4p1/openssh-clients-7.4p1-23.el7_9.x86_64.rpm
  inflating: test/openssh-7.4p1/openssh-server-7.4p1-23.el7_9.x86_64.rpm

# ll test/
total 4
drwxr-xr-x 2 root root 4096 Sep  5 09:17 openssh-7.4p1
image.png
# unzip --help

UnZip 6.00 of 20 April 2009, by Info-ZIP.  Maintained by C. Spieler.  Send
bug reports using http://www.info-zip.org/zip-bug.html; see README for details.

Usage: unzip [-Z] [-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir]
  Default action is to extract files in list, except those in xlist, to exdir;
  file[.zip] may be a wildcard.  -Z => ZipInfo mode ("unzip -Z" for usage).

  -p  extract files to pipe, no messages     -l  list files (short format)
  -f  freshen existing files, create none    -t  test compressed archive data
  -u  update files, create if necessary      -z  display archive comment only
  -v  list verbosely/show version info       -T  timestamp archive to latest
  -x  exclude files that follow (in xlist)   -d  extract files into exdir
modifiers:
  -n  never overwrite existing files         -q  quiet mode (-qq => quieter)
  -o  overwrite files WITHOUT prompting      -a  auto-convert any text files
  -j  junk paths (do not make directories)   -aa treat ALL files as text
  -U  use escapes for all non-ASCII Unicode  -UU ignore any Unicode fields
  -C  match filenames case-insensitively     -L  make (some) names lowercase
  -X  restore UID/GID info                   -V  retain VMS version numbers
  -K  keep setuid/setgid/tacky permissions   -M  pipe through "more" pager
  -O CHARSET  specify a character encoding for DOS, Windows and OS/2 archives
  -I CHARSET  specify a character encoding for UNIX and other archives

See "unzip -hh" or unzip.txt for more help.  Examples:
  unzip data1 -x joe   => extract all files except joe from zipfile data1.zip
  unzip -p foo | more  => send contents of foo.zip via pipe into program more
  unzip -fo foo ReadMe => quietly replace existing ReadMe if archive file newer

# unzip -l  openssh-7.4p1.zip

Archive:  openssh-7.4p1.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  09-05-2023 09:17   openssh-7.4p1/
   522276  08-08-2023 22:22   openssh-7.4p1/openssh-7.4p1-23.el7_9.x86_64.rpm
   670588  08-08-2023 22:22   openssh-7.4p1/openssh-clients-7.4p1-23.el7_9.x86_64.rpm
   470524  08-08-2023 22:23   openssh-7.4p1/openssh-server-7.4p1-23.el7_9.x86_64.rpm
---------                     -------
  1663388                     4 files

命令 unzip -l openssh-7.4p1.zip 的详细解读如下:

  • unzip: 用于解压缩zip格式的压缩文件的命令。
  • -l: 选项表示以列表形式显示压缩包中的文件列表。
  • openssh-7.4p1.zip: 指定要解压缩和查看的压缩文件为openssh-7.4p1.zip

因此,该命令的作用是以列表形式显示压缩包openssh-7.4p1.zip中的文件列表。命令的输出列出了压缩包中的每个文件的相关信息,包括文件名、长度、日期和时间等。
在这个例子中,压缩包中包含了4个文件,分别是:

  1. openssh-7.4p1/:一个目录,长度为0字节,日期和时间为09-05-2023 09:17。
  2. openssh-7.4p1/openssh-7.4p1-23.el7_9.x86_64.rpm:一个rpm文件,长度为522276字节,日期和时间为08-08-2023 22:22。
  3. openssh-7.4p1/openssh-clients-7.4p1-23.el7_9.x86_64.rpm:一个rpm文件,长度为670588字节,日期和时间为08-08-2023 22:22。
  4. openssh-7.4p1/openssh-server-7.4p1-23.el7_9.x86_64.rpm:一个rpm文件,长度为470524字节,日期和时间为08-08-2023 22:23。

总共压缩包中的文件占用了1663388字节。

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 220,492评论 6 513
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 94,048评论 3 396
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 166,927评论 0 358
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 59,293评论 1 295
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 68,309评论 6 397
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 52,024评论 1 308
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,638评论 3 420
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,546评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 46,073评论 1 319
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 38,188评论 3 340
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,321评论 1 352
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,998评论 5 347
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,678评论 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,186评论 0 23
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,303评论 1 272
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,663评论 3 375
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,330评论 2 358

推荐阅读更多精彩内容