Zip is one of the most popular archive file formats out there. With zip, you can compress multiple files or folders. This saves disk space and saves network bandwidth and transfers data to another machine faster. In addition, zip files can be decompressed easily on various platforms from Windows, Linux to macOS. This is why you can come across zip files everywhere.
In this tutorial, we will learn how to zip files on Linux in two ways.
How To Zip Files On Linux Using the Command Line
zip is a command that helps you create zip archives with the following syntax:
zip OPTIONS ARCHIVE_NAME FILES
zip is not installed by default in most Linux distributions, but you can easily install it using your distribution’s package manager:
Install zip on Ubuntu and Debian
sudo apt install zip
Install zip on CentOS and Fedora
sudo yum install zip
The zip command is straightforward:
zip [option] archivename.zip filename1 filename2
When specifying a zip archive filename, if you omit the .zip extension, it will be added automatically when creating the file.
To compress the entire contents of a directory, you would use the -r option:
zip -r archivename.zip directory_name
You can also compress multiple folders at once:
zip -r archivename.zip directory_name1 directory_name2 file1 file1
If you have sensitive information that needs to be protected, you can encrypt it using the -e option then enter and confirm the storage password:
zip -e archivename.zip directory_name
See more: Top 5 Lightest Linux Operating System
How To Zip Files On Linux Using the GUI
Although I use Ubuntu here, this method is very simple and quite similar to other Linux distributions.
First, go to the folder containing the file or folder to be compressed, right-click and select Compress.
You can now create a compressed archive in zip, tar.xz or 7z format. If you’re wondering, all three are different compression algorithms that you can use to compress your files. Here you will choose zip.
Give the name you want and click Create.
It won’t take long and you should see an archive appear in the current directory.
In case you want to set a password for the zip file, you will need to do the following:
Find and open the Archive Manager software
Drag and drop the file or folder to be compressed here, click Create Archive
At this step, you can name, choose how to compress (zip) and save the file location. To create a password for the archive, select Other Options.
Enter the password and click Save to create the zip file.
It is done. You have successfully created the zip files on Linux. Hope this little tip will help you quickly create a zip file in Linux operating systems.