由shell脚本创建的Zip文件夹无法打开

时间:2016-10-20 04:46:38

标签: shell unix zip

我使用以下脚本压缩文件夹及其内容: -

cd /home/fs/Inbnd/
pwd

tar -cvf Image_test_new.zip Image

chmod 777 *
chown fusionc:staff *

文件image.zip已成功创建。但该文件未打开并显示错误:

Error 我用来压缩的条款是否有错误?

3 个答案:

答案 0 :(得分:1)

tar -cvf制作tar球,而不是zip存档。在尝试在Windows中打开它之前,您可以在Linux中验证这一点。

touch not_going_to_be_a_zip
tar -cvf not_really_a.zip not_going_to_be_a_zip
unzip not_really_a.zip
Archive:  not_really_a.zip
  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.
unzip:  cannot find zipfile directory in one of not_really_a.zip or
        not_really_a.zip.zip, and cannot find not_really_a.zip.ZIP, period.

zip实用程序可以很好地制作zip存档。

touch will_be_a_zip
zip i_am_a.zip will_be_a_zip      Archive:  i_am_a.zip
    testing: will_be_a_zip            OK
No errors detected in compressed data of i_am_a.zip.
unzip -t i_am_a.zip
  Archive:  i_am_a.zip
    testing: will_be_a_zip            OK
No errors detected in compressed data of i_am_a.zip.

注意:unzip -t只会测试存档,在Windows中尝试之前请确保它没问题。

答案 1 :(得分:0)

如果您无法使用 zip / unzip 等标准方法,并且您的计算机上安装了 JDK ,那么您可以使用 jar JDK&bin文件夹中的实用程序。

要压缩文件

jar cvf zip_file_name.zip image.jpg

唯一的开销是它将添加一个META-INF文件夹,其中包含一个名为MANIFEST.MF的文件,您可以在解压缩zip文件后将其删除。

答案 2 :(得分:-1)

尝试使用zip命令而不是tar命令。

相关问题