在Linux上如何制作zip文件?

14

zip -h 好像有点混乱!我只想知道如何从目录创建 .zip 文件。感谢啦

5个回答

16
zip -r archive.zip dir_to_zip

从 man zip

-r  
   --recurse-paths
          Travel the directory structure recursively; for example:

                 zip -r foo.zip foo

          or more concisely

                 zip -r foo foo

In  this  case, all  the  files and directories in foo are saved in a zip archive
named foo.zip,including files with names starting with ".", since  the  recursion
does not use the shell's file-name substitution mechanism...

即使它正常运作,我仍建议你使用7z (http://www.7-zip.org/)。

  7za a directory.7z  directory

它具有更好的压缩性,而且它是开源的,GNU LGPL许可证,可以自由地在Windows、Linux、BSD上使用...

顺便说一句,它可以创建/打开7z、XZ、BZIP2、GZIP、TAR、ZIP和WIM文件,
并且只能打开解压:ARJ、CAB、CHM、CPIO、CramFS、DEB、DMG、FAT、HFS、ISO、LZH、LZMA、MBR、MSI、NSIS、NTFS、RAR、RPM、SquashFS、UDF、VHD、WIM、XAR和Z。

[他们应该为我的广告付费 :-)]


6
在Linux操作系统中,虽然它可以进行压缩文件,但是您应该使用以下命令进行压缩: tar
tar -jcvf archive_name.tar /path/to/directory_to_compress

输入目录 /path/to/directory_to_compress 的压缩文件将被命名为archive_name.tar。

要解压,请执行以下操作:

tar -xvf archive_name.tar

tar 工具在 Windows 10 上也是可用的,您可以从https://www.libarchive.org/downloads/下载安装它,这将使您获得 bsdtar.exe。我刚刚使用它成功地解压了一个在 Linux 上创建的 xxx.tar 文件。


2
那不是ZIP,你必须同意。它不是可移植的。 - Eugene Mayevski 'Callback
确切地说,否则我为什么要问如何制作zip呢? - Dan

3
这应该很简单和简短。压缩。
tar -zcvf filename.tar myflie.sql

解压缩
tar -xvzf filename  

如果您对使用选项更感兴趣

z - 通过gzip实现过滤
j - 通过bzip2实现过滤
c - 创建归档文件
v - 显示进度
x - 提取归档文件
f - 文件名

干杯


3
我认为这会对你有所帮助。
zip -r new_zip_file directory_name

其中,"new_zip_file"是你想要创建的.zip文件的名称,而"directory_name"则是你想要在zip中压缩的文件夹。


1
通常使用tar创建一个未压缩的归档文件,然后使用gzip或bzip2对该归档文件进行压缩。相应的gunzip和bunzip2命令可用于解压缩该归档文件,或者您可以在tar命令上使用标志来执行解压缩。
如果您特别指的是Zip文件格式,则可以直接使用zip和unzip命令。
要压缩:
zip squash.zip file1 file2 file3

或者压缩一个目录

zip -r squash.zip dir1

解压缩:

要解压缩:

unzip squash.zip

这将在您当前的工作目录中解压缩它。
来源 :: 这里

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接