Linux zip Command
- What we learn is not only technology, but also dreams!
Linux Tutorial
Shell Tutorial
Linux Reference Manual
Deep Exploration
- Network Services
- Programming
- Computer Science
- Development Tools
- Software
- Web Design and Development
- Programming Languages
- Scripting
- Web Service
- Scripting Languages
Linux zip Command
The Linux zip command is used to compress files.
zip is a widely used compression program, and the compressed file has the extension .zip.
Unlike gzip or bzip2, zip can compress multiple files or entire directories while preserving the directory structure.
zip is also widely supported across platforms (such as Windows, macOS).
Syntax
zip output.zip file1 file2 ...
output.zip: The name of the generated compressed file.file1 file2 ...: Files or directories to compress.
Options parameters:
-r: Recursively compress directories and all files in subdirectories.-e: Set password protection for the compressed file.-q: Quiet mode, does not display compression process.-v: Display detailed compression process.-x: Exclude certain files or directories from compression.-m: Delete original files after compression.-0to-9: Specify compression level,-0means store without compression,-9means highest compression ratio, default is-6.
Examples
Compress a single file
zip archive.zip example.txt
This command will compress example.txt into archive.zip.
Compress multiple files
zip archive.zip file1.txt file2.txt file3.txt
This command will compress file1.txt, file2.txt, and file3.txt into archive.zip.
Recursively compress directories
zip -r archive.zip directory/
This command will recursively compress all files in the directory/ directory and its subdirectories while preserving the directory structure.
Compress with password protection
zip -e archive.zip file.txt
This command will compress file.txt with password protection. A password will be required during decompression.
Exclude specific files
zip -r archive.zip directory/ -x "*.log"
This command will compress all files in the directory/ directory but exclude all .log files.
Delete original files after compression
zip -m archive.zip file.txt
This command will compress file.txt into archive.zip and delete the original file file.txt.
Decompress files
Use the unzip command to decompress .zip files:
unzip archive.zip
This will decompress the archive.zip file to the current directory, preserving the original directory structure and files.
YouTip