Linux上是否有任何命令可将.tar.gz文件转换为.zip? [英] Is there any command on Linux to convert .tar.gz files to .zip?

查看:91
本文介绍了Linux上是否有任何命令可将.tar.gz文件转换为.zip?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经收到.tar.gz类型的文件,但是我正在使用的应用程序仅接受.zip文件.我需要一种简单的方法来将.tar.gz文件转换为.zip,而不会丢失任何数据.

I've received files in .tar.gz type but the application I'm using only accepts .zip files. I need an easy way of converting .tar.gz files to .zip without loosing any of the data.

重命名为.zip是否行得通?我已经尝试过了,但是当我单击该文件时,它显示为无效文件.

Does renaming to .zip will work? I've tried it but when I click on the file it's showing it as a invalid file.

对此有任何想法或投入吗?

Any thoughts or inputs for this?

推荐答案

您可能可以将存档 foo.tar.gz 转换为压缩存档 foo.zip ,并使用与此类似的命令:

You can probably convert your archive foo.tar.gz into a zipped archive foo.zip with a command similar to this one:

tar xzOf foo.tar.gz |zip foo.zip $(tar tf foo.tar.gz)

详细信息: tar xzOf foo.tar.gz 将压缩后的( z )存档提取( x )到标准输出( O ).此处 f 用于提供输入文件名.

In details: tar xzOf foo.tar.gz extracts (x) the gzipped (z) archive to standard output (O). Here f is used to provide the input file name.

标准输入通过管道传递到 zip 中,其第一个参数是要生成的压缩文件的名称.以下参数是要压缩的文件的列表,我们可以使用 t 命令直接从 tar 获取,并在初始 .tar.gz 文件.

Standard input is piped into zip, whose first argument is the name of the zipped file to produce. The following argument is the list of the files to compress, that we can obtain directly from tar with the t command, run on the initial .tar.gz file.

编辑:我认为上述单行代码可以轻松地将tar存档转换为zip文件.大约一年后再次读取该命令,结果发现它看起来很破损:它只是从tar存档中获取文件名,而从原始文件(未压缩)中提取zip(如果它们仍在磁盘上).我看不到如何生成简单的单行代码,因为您显然无法在命令行上将文件的名称和内容同时提供给 zip (另请参见

I thought the above one-liner could be used to easily convert a tar archive into a zip file. Reading again the command one year later or so, it turns out it looks badly broken: it just takes the names of the files from the tar archive, and zip from the original files (non-compressed), if they are still on the disk. I don't see how to produce a simple one-liner, since you apparently cannot provide both the name and the contents of the file to zip on the command line (see also this question and its answers).

因此,我们可能需要执行两个步骤:首先从tar存档中解压缩,然后再次压缩.像这样:

So we probably need two steps to do this: first uncompress from the tar archive, then compress again. Something like:

tar xzf foo.tar.gz && zip foo.zip $(tar tf foo.tar.gz)

我们还可以添加第三部分来删除临时解压缩的文件:&&rm -r-$(tar tf foo.tar.gz),但请谨慎操作,确保不要擦除您想保留的内容.

We can also add a third part to remove the temporarily decompressed files: && rm -r -- $(tar tf foo.tar.gz), but be cautious and make sure this does not erase stuff you want to keep.

有关更多详细信息,请查看 zip tar 实用程序的手册页.

For more details, have a look at the manual pages of zip and tar utilities.

这篇关于Linux上是否有任何命令可将.tar.gz文件转换为.zip?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆