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.
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?
Simply right-click the item you want to compress, mouseover compress, and choose tar. gz. You can also right-click a tar. gz file, mouseover extract, and select an option to unpack the archive.
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)
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.
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.
Edit: 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).
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)
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.
For more details, have a look at the manual pages of zip
and tar
utilities.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With