Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when `tar` a `.zip` on Linux

Tags:

linux

macos

zip

tar

I zipped a directory on my Mac OSX with the zip command line and -r option. I scp the .zip to a cluster operating on Linux.

If I try to decompress the .zip with

tar -vxzf foo.zip

on my machine it works. But the same command doesn't work on the cluster. I get the error

gzip: stdin has more than one entry--rest ignored
tar: Child returned status 2
tar: Error is not recoverable: exiting now

How can I solve this issue?

like image 906
Remi.b Avatar asked Mar 09 '15 20:03

Remi.b


People also ask

Can tar be used on zip files?

If you're already familiar with zip files, this should be pretty easy to get because they work in the same way. While a zip file has the extension . zip, a tar file can have .

How do I unzip a .zip file with tar?

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.

Why does Linux use tar instead of zip?

tar gz is better for Linux/Unix as it retains permissions, such as "executable" on scripts. OS X's Archive Utility and zip / unzip preserve permissions, but there might be other utilities that don't.


2 Answers

The tar command is for unpacking TAR archives, not zip files. You should either use the unzip command instead of tar:

unzip foo.zip

Or make a tar.gz archive on the Mac side instead of a zip file

tar -cvzf foo.tar.gz ....

which you can unpack with your existing tar command on the Linux side.

like image 64
Ian Roberts Avatar answered Sep 21 '22 08:09

Ian Roberts


This error :

gzip: stdin has more than one entry--rest ignored

Means that tar is trying to decompress your zip archive as if it was a gzip archive, that doesn't always work (see "Files created by zip can be uncompressed by gzip only if they have a single member compressed with the 'deflation' method" for more info).

You should use unzip foo.zip instead to decompress a zip archive.

like image 35
tux3 Avatar answered Sep 20 '22 08:09

tux3