=> Zip files do not support Linux-style ownership information. The extracted files are owned by the user that runs the command. To preserve the file ownership and permissions, use the tar command.
=> If the archive name doesn’t end with .zip, the extension is added automatically unless the archive name contains a dot. zip
Table of Contents
- 1 Install ZIP in Linux:-
- 2 The -r Option Allows You To Traverse The Whole Directory Structure Recursively:
- 3 By Default, The Zip Command Prints The Names Of The Files Added To The Archive And The Compression Method.
- 4 Compression Methods and Levels
- 5 Creating a Password Protected ZIP File
- 6 Creating Split Zip File
- 7 Some Extra Zip Command Examples
Install ZIP in Linux:-
Install zip on Ubuntu and Debian
sudo apt install zip
Install zip on CentOS and Fedora
sudo yum install zip
The -r Option Allows You To Traverse The Whole Directory Structure Recursively:
zip -r archive_name.zip directory_name
You can also add multiple files and directories in the same archive:
zip -r archive_name.zip directory_name1 directory_name2 file1 file1
By Default, The Zip Command Prints The Names Of The Files Added To The Archive And The Compression Method.
To suppress the output of the zip command, use the -q option:
zip -q archive_name.zip filename1 filename2 filename3
Compression Methods and Levels
The default compression method of Zip is deflate. If the zip utility determines that a file cannot be compressed, it simply stores the file in the archive without compressing it using the store method.
In most Linux distributions, the zip utility also supports the bzip2 compression method.
To specify a compression method, use the -Z option.
zip -r -Z bzip2 archive_name.zip directory_name
...
adding: sub_dir/ (stored 0%)
adding: sub_dir/file1 (bzipped 52%)
adding: sub_dir/file2 (bzipped 79%)
The Default Compression Level Is -6. When Using -0, All Files Will Be Stored Without Compression. -9 Will Force The Zip Command To Use An Optimal Compression For All Files.
zip -9 -r archive_name.zip directory_name
The higher the compression level, the more CPU-intensive the zip process is, and it will take more time to complete.
Creating a Password Protected ZIP File
If you have sensitive information that needs to be stored in the archive, you can encrypt it using the -e option:
zip -e archive_name.zip directory_name
The command will be prompted to enter and verify the archive password:
Enter password:
Verify password:
Creating Split Zip File
Imagine you want to store the Zip archive on a file hosting service that has a file size upload limit of 1GB, and your Zip archive is 5GB.
You can create a new split Zip file using the -s option followed by a specified size. The multiplier can be k (kilobytes), m (megabytes), g (gigabytes), or t (terabytes).
zip -s 1g -r archive_name.zip directory_name
The command above will keep creating new archives in a set after it reaches the specified size limit.
archive_name.zip
archive_name.z01
archive_name.z02
archive_name.z03
archive_name.z04
Some Extra Zip Command Examples
Create a Zip archive named archive_name.zip containing all the files in the current directory.
zip archive_name *
Same as above, including the hidden files (files starting with a dot):
zip archive_name .* *
Create a Zip archive named archive_name.zip containing all MP3 files in the current directory without compressing the files.
zip -0 archive_name *.mp3