← 返回命令列表

Linux command

zip 命令

网络

复制后可按需替换文件名、目录或参数。

常用示例

Create a ZIP archive

zip [archive.zip] [file1] [file2]

Create archive from directory

zip -r [archive.zip] [directory/]

Add files to existing archive

zip [archive.zip] [newfile.txt]

Create archive with compression level

zip -9 [archive.zip] [files]

Create encrypted archive

zip -e [archive.zip] [files]

Exclude files from archive

zip -r [archive.zip] [directory/] -x "*.log"

Update only changed files

zip -u [archive.zip] [files]

Create archive excluding directory

zip -r [archive.zip] [dir/] -x [dir/subdir/*]

Delete file from archive

zip -d [archive.zip] [file_to_remove]

Move files into archive (delete originals)

zip -m [archive.zip] [file1] [file2]

Create a split archive with 100 MB parts

zip -s [100m] [archive.zip] [files]

Test archive integrity

zip -T [archive.zip]

说明

zip creates and modifies ZIP archives, a widely supported compressed archive format. It compresses files using the DEFLATE algorithm (or store without compression) and packages them with metadata including names, timestamps, and permissions. ZIP archives are cross-platform compatible and supported natively on Windows, macOS, and most Unix systems. The format supports directory structures, encryption, and archives spanning multiple files. zip can create new archives, add files to existing ones, update changed files, or delete entries. It's commonly used for file distribution, backups, and data exchange.

参数

-r
Recurse into directories.
-9
Maximum compression.
-0
Store only (no compression).
-e
Encrypt archive (prompts for password).
-P _password_
Use specified password.
-u
Update only changed files.
-f
Freshen (update existing entries only).
-d
Delete entries from archive.
-x _pattern_
Exclude files matching pattern.
-i _pattern_
Include only matching files.
-j
Junk directory paths.
-q
Quiet mode.
-v
Verbose output.
-m
Move files into archive (delete originals after successful archiving).
-g
Grow (append to) an existing archive.
-T
Test archive integrity after creation. Aborts if the check fails.
-@
Read file list from stdin.
-s _size_
Split archive into pieces of the given size (e.g. `100m`, `1g`).
-sf
Show the files that would be operated on, then exit without creating the archive.
-FS
Sync archive contents with the filesystem: add new files, update changed files, and remove entries not on disk.
-y
Store symbolic links as links rather than following them.

FAQ

What is the zip command used for?

zip creates and modifies ZIP archives, a widely supported compressed archive format. It compresses files using the DEFLATE algorithm (or store without compression) and packages them with metadata including names, timestamps, and permissions. ZIP archives are cross-platform compatible and supported natively on Windows, macOS, and most Unix systems. The format supports directory structures, encryption, and archives spanning multiple files. zip can create new archives, add files to existing ones, update changed files, or delete entries. It's commonly used for file distribution, backups, and data exchange.

How do I run a basic zip example?

Run `zip [archive.zip] [file1] [file2]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -r do in zip?

Recurse into directories.