One of the most often used file formats for archives is zip. One or even more compressed files and directories can be found in a Zip file, a data container type. Files that have been compressed (zipped) use less disk space and move more quickly from one machine to another.
Zip files can be readily extracted on Windows, macOS, and Linux PCs using the utilities provided for each operating system. In Linux, you'll often unzip files on a regular user. But how do you zip a folder in Linux? That question is answered in this article.
Want to know more about Linux? Check out our guide on how to check your Linux version using the check-linux-version-command command.
Prerequisites of zipping a file in Linux
Zip support is typically installed, although there is no harm in checking. Use the command below after opening a terminal:
zip –version
If you can see some details on the Zip version, you already have Zip installed. Run the command below to install zip and unzip support in Ubuntu and Debian-based distributions if it says "zip command not found."
sudo apt install zip unzip
Zip a file in Linux using Command Line
The zip command's syntax is rather simple to understand:
zip [option] output_file_name input1 input2
Use the following command if your primary goal is to build a zip folder from a collection of files and directories:
zip -r output_file.zip file1 folder1
Recursing into directories and compressing their contents are also features of the -r option. The output files' .zip extension is not required because it is added by default. You should notice the files being added to the compressed folder during the zip operation.
Zipping a file in Linux using GUI
In desktop Linux, compressing a file or folder only requires a few mouse clicks. Navigate to the folder containing the files (or folders) you want to include in the zip folder. Choose the files and folders in it. Right-click now, and then choose Compress. The same procedure applies to single files.
You can now make a compressed archive file in zip, tar, or 7z formats. In case you were curious, these three are different compression methods that you can employ to compress your data. Give it the name you want, then select Create. You should notice an archive file in the same location quickly after.
? Elevate your online ventures with our Linux VPS hosting - offering top-notch resources and a user-friendly interface that's perfect for beginners and experts alike. ???
Compression Levels and Techniques
Deflate is Zip's default technique of compression. When a file cannot be compressed, the zip program stores it in the archive without using the store method of compression. The zip utility in most Linux distributions also supports the bzip2 compression algorithm.
Use the -Z option to select a compression technique.
zip -r -Z bzip2 archivename.zip directory_name
When using the zip command, you can use a number from 0 to 9 that is prefixed with a dash to determine the compression level.
The compression level, by default, is -6. All files will be uncompressed when using the value -0. Using a compression ratio of -9 will require Zip to apply the best compression to all files.
For instance, if you wanted to utilize compression level -9, you would type:
zip -9 -r archivename.zip directory_name
The zip operation is CPU-intensive and takes longer to complete the greater the compression level.
Making a ZIP file with a password
Utilizing the -e option, you can encrypt any sensitive data that must be kept in the archive:
zip -e archivename.zip directory_name
The archive password must be entered and verified by the command:
Enter password:
Verify password:
Creating Split Zip File
Imagine that your Zip archive is 5GB and that you want to store it on a service that hosts files and has a 1GB upload limit. The -s option and a predetermined size can produce a new split Zip file. The multiplier can be k, m, g, or t.
zip -s 1g -r archivename.zip directory_name
When a set hits the provided size limit, the aforementioned command will continue to create new archives.
archivename.zip
archivename.z01
archivename.z02
archivename.z03
archivename.z04
Conclusion
The most used archive file type for files and directories is ZIP. Files can be compressed into archived formats to save disk space and network bandwidth. On Linux computers, the tape archive (tar) format is more prevalent; however, ZIP is also frequently used because of its ubiquity.
Linux has the zip function for ZIP file compression. Alternatively, zipping a file in Linux is also feasible through the GUI. For more information on checking your Linux version, which is crucial for compatibility, refer to our guide on "How to Check Linux Version Command".
People also read: