如何在 Linux 上制作 zip 文件?

Dan*_*Dan 6 linux zip command-line-interface

zip -h 令人困惑!我只想知道如何从目录中制作 .zip。知乎

Has*_*tur 7

zip -r archive.zip dir_to_zip
Run Code Online (Sandbox Code Playgroud)

从男人拉链

-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...
Run Code Online (Sandbox Code Playgroud)

即使它运行良好,我也想向您推荐 7z(http://www.7-zip.org/)。

  7za a directory.7z  directory
Run Code Online (Sandbox Code Playgroud)

它有更好的压缩,它是开源的,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。

[他们应该付钱给我做广告:-)]


Sco*_*and 6

在 Linux 上,虽然它可以压缩,但你确实应该使用:

压缩

tar -jcvf archive_name.tar /path/to/directory_to_compress
Run Code Online (Sandbox Code Playgroud)

其中 archive_name.tar 将是输入目录 /path/to/directory_to_compress 的压缩版本

解压

tar -xvf archive_name.tar
Run Code Online (Sandbox Code Playgroud)

tar 在 Windows 10 上可用,您可以从 https://www.libarchive.org/downloads/安装它,这将为您提供 bsdtar.exe,我刚刚用它成功解压了在 linux 上创建的 xxx.tar 文件

  • 这不是 ZIP,您必须同意。它不便携。 (2认同)

RBr*_*dao 3

我想这会对你有帮助

zip -r new_zip_file directory_name
Run Code Online (Sandbox Code Playgroud)

其中“new_zip_file”是您要创建的 .zip 文件的名称,“directory_name”是您要在 zip 中压缩的文件夹。