通过示例解释 Linux Gunzip 命令通过示例解释 Linux Gunzip 命令通过示例解释 Linux Gunzip 命令通过示例解释 Linux Gunzip 命令
  • 文章
  • 正则表达式
    • 工具
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容
发表 admin at 2025年2月28日
类别
  • 未分类
标签

通过示例解释 Linux Gunzip 命令

在此页

  1. Linux gunzip 命令
  2. Q1。如何使用 gunzip 解压缩档案?
  3. Q2。如何使 gunzip 不删除存档文件?
  4. Q3。如何让 gunzip 将未压缩的文件放在其他目录中?
  5. 更多信息
  6. 结论

我们已经讨论过 Linux 中的 gzip 命令。对于初学者,该工具用于压缩或扩展文件。为了解压缩,该命令提供了一个命令行选项 -d,可以按以下方式使用:

gzip -d [compressed-file-name]

但是,有一个完全不同的工具可用于解压缩或扩展 gzip 创建的存档。有问题的工具是 gunzip。在本文中,我们将使用一些易于理解的示例来讨论 gunzip 命令。本教程中提到的所有示例/说明都已在 Ubuntu 22.04 上进行了测试。

Linux gunzip命令

所以现在我们知道可以使用 gzip -d 或 gunzip 命令恢复压缩文件。 gunzip 的基本语法是:

gunzip [compressed-file-name]

以下问答式示例应该可以让您更好地了解该工具的工作原理:

Q1。如何使用 gunzip 解压缩档案?

这非常简单 - 只需将存档文件的名称作为参数传递给 gunzip。

gunzip [archive-name]

例如:

gunzip file1.gz

Q2。如何使 gunzip 不删除存档文件?

正如您所注意到的,gunzip 命令会在解压缩后删除存档文件。但是,如果您希望保留存档,您可以使用 -c 命令行选项来实现。

gunzip -c [archive-name] > [outputfile-name]

例如:

gunzip -c file1.gz > file1

所以你可以看到在这种情况下存档文件没有被删除。

Q3.如何让 gunzip 将未压缩的文件放在其他目录中?

我们已经在之前的问答中讨论了 -c 选项。要使 gunzip 将解压缩的文件放在当前工作目录以外的目录中,只需在重定向运算符后提供绝对路径即可。

gunzip -c [compressed-file] > [/complete/path/to/dest/dir/filename]

这是一个例子:

gunzip -c file1.gz > /home/himanshu/file1

更多信息

以下详细信息 - 摘自 gzip/gunzip 的通用联机帮助页 - 对那些想了解更多命令的人应该是有益的:

       gunzip takes a list of files on its command line and replaces each file
       whose  name ends with .gz, -gz, .z, -z, or _z (ignoring case) and which
       begins with the correct magic number with an uncompressed file  without
       the  original extension.  gunzip also recognizes the special extensions
       .tgz and .taz as shorthands for .tar.gz and .tar.Z respectively.   When
       compressing, gzip uses the .tgz extension if necessary instead of trun
       cating a file with a .tar extension.

       gunzip can currently decompress files created by gzip,  zip,  compress,
       compress  -H  or pack.  The detection of the input format is automatic.
       When using the first two formats, gunzip checks a 32 bit CRC. For  pack
       and gunzip checks the uncompressed length. The standard compress format
       was not designed to allow consistency checks. However gunzip  is  some
       times  able  to  detect  a bad .Z file. If you get an error when uncom
       pressing a .Z file, do not assume that the .Z file  is  correct  simply
       because the standard uncompress does not complain. This generally means
       that the standard uncompress does not check its input, and happily gen
       erates  garbage  output.   The  SCO compress -H format (lzh compression
       method) does not include a CRC but also allows some consistency checks.

结论

就基本用法而言,与 Gunzip 相关的学习曲线并不多。我们几乎涵盖了初学者为了开始使用它而需要了解的有关此命令的所有内容。有关更多信息,请访问其手册页。

©2015-2025 艾丽卡 support@alaica.com