解压缩/提取.tar.gz文件需要什么命令?
我从客户端收到一个巨大的.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.
我需要使用什么命令来提取.tar.gz文件中的所有文件?
键入man tar
以获取更多信息,但此命令应该可以解决问题:
tar -xvzf community_images.tar.gz
为了进一步解释,tar将所有文件收集到一个包community_images.tar
。 gzip程序应用了压缩,因此是gz扩展。 所以命令做了几件事:
-
f
:这必须是命令的最后一个标志,tar文件必须紧跟在之后。 它告诉tar压缩文件的名称和路径。 -
z
:告诉tar使用g z ip解压缩归档 -
x
:tar可以收集文件或者收集文件。x
做后者。 -
v
:让tar谈了很多。 V erbose输出显示所有正在提取的文件。
如果要将文件解压缩到特定目标,可以添加-C /destination/path/
确保首先创建目录,在这种情况下:〜/ Pictures / Community
例:
mkdir ~/Pictures/Community tar xf community_images.tar.gz -C /home/emmys/Pictures/Community/
如果你考虑告诉tar到e X tract一个文件,你可以很容易地记住它
注意:请记住,您可以在手册页内搜索?
+要查找的术语,然后是n
和N
转到您要查找的术语的下一个或上一个实例。
在某些时候, tar
升级为自动解压缩。 你现在需要的只是:
tar xf community_images.tar.gz
同样的解释适用:
-
f
:这必须是命令的最后一个标志,tar文件必须紧跟在之后。 它告诉tar压缩文件的名称和路径。 -
x
:e x处理文件。
请注意命令标志缺少连字符。 这是因为大多数版本的tar都允许gnu和bsd样式选项(简单来说,gnu需要连字符,bsd不需要)。
如果您无法使用提取.tar.gz
文件
tar -xvzf fileName.tar.gz
尝试使用提取
tar xf fileName.tar.gz
记住tar
所有标志都很乏味。 强制性XKCD:
因此我用Python制作了自己的小脚本来做到这一点。 快速,脏, cp
like使用:
#!/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()
使用它如下:
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。 - tar
-xf
archive.tar#从archive.tar
提取所有文件。
您也可以在第一步中执行此操作:
gunzip community_images.tar.gz
然后你有文件:community_images.tar
第二步是:
tar -xvf community_images.tar
并且将提取* .tar文件。