我需要什么命令来解压缩/提取a。焦油。gz文件?

我收到了一个巨大的。焦油。来自客户端的gz文件,其中包含大约800mb的图像文件(未压缩时)。 我们的托管公司的ftp速度很慢,所以在本地提取所有文件并通过ftp发送是不实际的。 我能够ftp。焦油。gz文件到我们的托管站点,但是当我ssh到我的目录并尝试使用unzip时,它给了我这个错误:

[esthers@clients locations]$ unzip community_images.tar.gzArchive:  community_images.tar.gz  End-of-central-directory signature not found.  Either this file is not a zipfile, or it constitutes one disk of a multi-part archive.  In the latter case the central directory and zipfile comment will be found on the last disk(s) of this archive.note:  community_images.tar.gz may be a plain executable, not an archiveunzip:  cannot find zipfile directory in one of community_images.tar.gz or community_images.tar.gz.zip, and cannot find community_images.tar.gz.ZIP, period.

我需要使用什么命令来提取a中的所有文件。焦油。gz文件?

类型 man tar 欲了解更多信息,但这个命令应该做的伎俩:

tar -xvzf community_images.tar.gz

进一步解释一下, tar 将所有文件收集到一个包中, community_images.tar. Gzip程序应用压缩,因此 gz 延伸。 所以这个命令做了一些事情:

  • f:这必须是命令的最后一个标志,和tar file必须紧接着。 它告诉tar压缩文件的名称和路径。
  • z:告诉tar使用g解压缩存档知识产权
  • x:tar可以收集文件或ex道他们。 x 做后者。
  • v:使焦油谈了很多。 Verbose输出显示您正在提取的所有文件。

提取成 custom文件夹,添加 -C 选项与您选择的文件夹名称:

tar -xvzf community_images.tar.gz -C some_custom_folder_name

如果您希望将文件提取到特定目标,则可以添加 -C /destination/path/
确保您首先制作目录,在这种情况下:~/Pictures/Community

例子::

mkdir ~/Pictures/Communitytar xf community_images.tar.gz -C /home/emmys/Pictures/Community/

你可以很容易地记住它,如果你考虑告诉 焦油 到e X a区 F

gif of process done at terminal

注意事项: 记住,你可以在手册页内搜索 ?+术语寻找,然后 nN 转到您要查找的术语的下一个或上一个实例。

在某些时候 tar 升级为自动解压缩。 你现在需要的是:

tar xf community_images.tar.gz

同样的解释也适用:

  • f:这必须是命令的最后一个标志,和tar file必须紧接着。 它告诉tar压缩文件的名称和路径。
  • xx道的文件。

请注意命令标志缺少连字符。 这是因为大多数版本的tar都允许gnu和bsd样式选项(简单来说,gnu需要连字符,bsd不)。

记住所有标志 tar 可能很乏味。 强制性XKCD:

enter image description here

因此,我在Python中制作了自己的小脚本来做到这一点。 快,脏, cp-像在使用:

#!/usr/bin/env python3import tarfile,sys,ostf = tarfile.open(name=sys.argv[1],mode='r:gz')where = '.'if len(sys.argv) == 3:    where = sys.argv[2]tf.extractall(path=where)tf.close()

就这么用吧:

myuntar.py archive.tar

另见类似 解压缩zip档案的脚本.

快速回答:

tar -xvf  <.tar file> or <.tar.xz file>tar -xzvf <.tar.gz file>tar -xjvf <.tar.bz2 file>

[注意事项]:

  • -v 详细列出处理的文件。
  • -z 通过gzip过滤存档。
  • -f 使用存档文件或设备存档。
  • -x 从存档中提取文件。
  • -j bzip2。
  • 焦油 -xf 存档。tar#从 archive.tar.

如果你不能提取 .tar.gz 文件使用

tar -xvzf fileName.tar.gz

尝试使用提取

tar xf fileName.tar.gz

你也可以在第一步做到这一点:

gunzip community_images.焦油。gz

然后你有文件:community_images。焦油

第二步是:

tar-xvf community_images.焦油

和*。将提取tar文件。

tar xvf文件。焦油。gz

  • 提取物x
  • v为verbose(列表文件)
  • 文件名的f是下一个

任何远程现代版本的tar都应该自动检测存档是否被压缩,并为您添加"z"。