Emm*_*myS 983 gzip compression extract unzip tar
我从客户端收到了一个巨大的 .tar.gz 文件,其中包含大约 800 mb 的图像文件(未压缩时)。我们托管公司的 ftp 非常慢,因此在本地提取所有文件并通过 ftp 发送它们是不切实际的。我能够将 .tar.gz 文件 ftp 到我们的托管站点,但是当我 ssh 进入我的目录并尝试使用 unzip 时,它给了我这个错误:
[esthers@clients locations]$ unzip community_images.tar.gz
Archive: 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 archive
unzip: 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.
Run Code Online (Sandbox Code Playgroud)
我需要使用什么命令来提取 .tar.gz 文件中的所有文件?
dje*_*kyb 1621
键入man tar以获取更多信息,但此命令应该可以解决问题:
tar -xvzf community_images.tar.gz
Run Code Online (Sandbox Code Playgroud)
为了进一步解释,将tar所有文件收集到一个包中,community_images.tar. gzip 程序应用了压缩,因此gz扩展了。所以这个命令做了几件事:
f:这必须是命令的最后一个标志,而焦油˚F ILE后必须立即进行。它告诉 tar 压缩文件的名称和路径。z: 告诉 tar 使用 g z ip解压缩档案x:焦油可以收集文件或E X道他们。x是后者。v: 让 tar 说话很多。详细输出显示所有正在提取的文件。要解压缩到ç ustom文件夹,添加-C您所选择的文件夹名称选项:
tar -xvzf community_images.tar.gz -C some_custom_folder_name
Run Code Online (Sandbox Code Playgroud)
Jor*_*are 189
如果您希望将文件解压缩到特定目的地,您可以添加
确保首先创建目录,在这种情况下:~/Pictures/Community-C /destination/path/
例子:
mkdir ~/Pictures/Community
tar xf community_images.tar.gz -C /home/emmys/Pictures/Community/
Run Code Online (Sandbox Code Playgroud)
您可以轻松地记住它,如果你考虑告知焦油到E X道一˚F ILE

注意:请记住,您可以使用?+term在手册页中进行搜索,然后使用n和N转到您正在查找的术语的下一个或上一个实例。
dje*_*kyb 123
在某些时候tar升级为自动解压缩。你现在需要的是:
tar xf community_images.tar.gz
Run Code Online (Sandbox Code Playgroud)
同样的解释适用:
f:这必须是命令的最后一个标志,而焦油˚F ILE后必须立即进行。它告诉 tar 压缩文件的名称和路径。x:电子X道的文件。请注意命令标志缺少连字符。这是因为大多数版本的 tar 允许 gnu 和 bsd 样式选项(简单地说,gnu 需要连字符,bsd 不需要)。
Ser*_*nyy 16
记住所有标志tar可能很乏味。强制性 XKCD:
因此,我用 Python 制作了自己的小脚本来做到这一点。快速,肮脏,cp- 用法类似:
#!/usr/bin/env python3
import tarfile,sys,os
tf = 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()
Run Code Online (Sandbox Code Playgroud)
像这样使用它:
myuntar.py archive.tar
Run Code Online (Sandbox Code Playgroud)
另请参阅用于解压缩 zip 档案的类似脚本。
Ben*_*ari 12
tar -xvf <.tar file> or <.tar.xz file>
tar -xzvf <.tar.gz file>
tar -xjvf <.tar.bz2 file>
Run Code Online (Sandbox Code Playgroud)
[注意]:
-v 详细列出已处理的文件。-z 通过 gzip 过滤存档。-f 使用存档文件或设备 ARCHIVE。-x 从存档中提取文件。-j bzip2。-xfarchive.tar中#从提取所有文件archive.tar。