Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux zip command

Linux zip command

Linux Command Reference Linux Command Reference

The Linux zip command is used to compress files.

zip is a widely used compression program; compressed files have the extension .zip.

Unlike gzip or bzip2, zip can compress multiple files or an entire directory and preserve the directory structure.

zip is also widely supported across platforms (such as Windows and macOS).

Syntax



zip [options] output.zip file1 file2 ...

options (parameter options):

Example

Compress a single file



zip archive.zip example.txt

This command compresses example.txt into archive.zip.

** Compress multiple files**



zip archive.zip file1.txt file2.txt file3.txt

This command compresses file1.txt, file2.txt, and file3.txt into archive.zip.

** Recursively compress a directory**

zip -r archive.zip directory/

This command recursively compresses all files in the directory and its subdirectories, preserving the directory structure.

** Compress and set password protection**



zip -e archive.zip file.txt

This command compresses file.txt and sets password protection; a password must be entered when extracting.

** Exclude specific files**



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

This command compresses all files under the directory/ directory, but excludes all .log files.

** Delete original files after compression**



zip -m archive.zip file.txt

This command compresses file.txt into archive.zip and deletes the original file file.txt.

** Decompress a file**

Use the unzip command to extract .zip files:



unzip archive.zip

This extracts the archive.zip file into the current directory, preserving the original directory structure and files.

Linux Command Reference Linux Command Reference