「zip」- 功能 | 特性

更新 Zip 文件

linux – Sync zip file with folder? – Stack Overflow

-FS / –filesync

Synchronize the contents of an archive with the files on the OS. Normally when an archive is updated, new files are added and changed files are updated but files that no longer exist on the OS are not deleted from thearchive. This option enables a new mode that checks entries in the archive against the file system. If the file time and file size of the entry matches that of the OS file, the entry is copied from the old archive insteadof being read from the file system and compressed. If the OS file has changed, the entry is read and compressed as usual. If the entry in the archive does not match a file on the OS, the entry is deleted. Enabling thisoption should create archives that are the same as new archives, but since existing entries are copied instead of compressed, updating an existing archive with -FS can be much faster than creating a new archive. Also con‐sider using -u for updating an archive.

For this option to work, the archive should be updated from the same directory it was created in so the relative paths match. If few files are being copied from the old archive, it may be faster to create a new archive in‐stead.

Note that the timezone environment variable TZ should be set according to the local timezone in order for this option to work correctly. A change in timezone since the original archive was created could result in no timesmatching and recompression of all files.

This option deletes files from the archive. If you need to preserve the original archive, make a copy of the archive first or use the –out option to output the updated archive to a new file. Even though it may be slower,creating a new archive with a new archive name is safer, avoids mismatches between archive and OS paths, and is preferred.

查看 Zip 文件

View list of files in ZIP archive on Linux – Super User

The less utility is capable of peeking into a zip archive.

In fact, if you look at the outputs of unzip -l zipfile and less zipfile, you will find them to be identical.

忽略目录 / 忽略文件

-x files / –exclude files

  • zip -r foo foo -x \*.o \*.c

Q:忽略特殊文件?
A:我们暂时(10/21/2024)未找到忽略特殊文件的命令行选项,需要通过其他方式来处理。

退出状态 | Exit Code

zip(1): package/compress files – Linux man page

0 | normal; no errors or warnings detected.

2 | unexpected end of zip file.

3 | a generic error in the zipfile format was detected. Processing may have completed successfully anyway; some broken zipfiles created by other archivers have simple work-arounds.

4 | zip was unable to allocate memory for one or more buffers during program initialization.

5 | a severe error in the zipfile format was detected. Processing probably failed immediately.

6 | entry too large to be processed (such as input files larger than 2 GB when not using Zip64 or trying to read an existing archive that is too large) or entry too large to be split with zipsplit

7 | invalid comment format

8 | zip -T failed or out of memory

9 | the user aborted zip prematurely with control-C (or similar)

10 | zip encountered an error while using a temp file

11 | read or seek error

12 | zip has nothing to do

13 | missing or empty zip file

14 | error writing to a file

15 | zip was unable to create a file to write to

16 | bad command line parameters

18 | zip could not open a specified file to read

错误提示 … zip warning: could not open for reading: … 例如,zip 尝试添加 socket file 时,将产生该提示。但是,其并不会导致 zip 直接退出。

19 | zip was compiled with options not supported on this system

保存文件的元数据 | Metadata

zip – Preserving permissions while zipping – Unix & Linux Stack Exchange
linux – Unzipping file whilst getting correct permissions? – Super User

根据文档描述:

Dates, times and permissions of stored directories are not restored except under Unix. (On Windows NT and successors, timestamps are now restored.)

查看文件所有者、所属组、权限

unzip -Z

Info-Zip 3.0 SUPPORTS preserving files/dirs UNIX permissions and UID/GID ownership data.

unzip must be used with the -X flag.


unzip must run as root to set the files/dirs UID/GID.


unzip with the -K flag to also restore SUID/SGID/Sticky bits.

特殊文件的保存

–symlinks | 保存符号连接文件。