How to Zip and Unzip Files in Linux Terminal. In this post, we introduce Zip file, its advantages then show you how to Zip and Unzip files in Linux terminal.
Zip is a free and open source file and directory compression tool for Linux, MacOS, and Windows operating systems. A common file format that reduces the file and directory size and makes it easier to transfer files to other computers. The full form of Zip is “Zip Archive File” which supports lossless data compression. So you don’t need to worry to lose any information during compression or decompression. The Zip file format was created by Phil Katz and Gary Conway in 1989. It has the ability to add multiple files into a single compressed file. A Zip file is considered a base file format by many programs and software.
Unzip is a file decompression utility used to extract the zipped file. In simple words, Unzipping is the process of extracting files from a zipped archive.
Advantages of Zip File
One of the major advantages of a Zip file is that it saves storage space and increases the efficiency of your computer.
Provides an effective way to transfer files via email and chat.
The Zip file also maintains your privacy by encrypting your file content.
We have arrived to the main part of the article. Please follow and learn How to Zip and Unzip Files in Linux Terminal.
By default, the Zip and Unzip packages are available in the default repository of all major Linux operating systems. Install it using any package manager.
For Ubuntu and Debian based operating systems install Zip and Unzip utilities with the following command.
apt install zip unzip -y
For CentOS, RHEL and Fedora based operating systems, install Zip and Unzip utilities with the following command.
dnf install zip unzip -y
After installing both utilities, verify the Zip package version with the following command.
zip --version
You should see the Zip package information on the following screen.
What is more, Zip also allows you to create a password protected Zip archive. This helps you to protect your important files. Use the -e option with the Zip command to create a password protected file.
The following command creates a password protect Zip archive of the file named protected1.
zip -ev protected1.zip protected1
You will be asked to provide a password as shown below.
Exclude Files from the Zip Archive
Please use the -x option if you don’t want to include a specific file in a Zip archive. The following command excludes a file named cloud1 from the clouddir directory.
zip -xrv clouddir.zip cloud1
Create a Split Zip File
You may need to split the Zip file if your created Zip file is very large and unable to send it via email due to the size limit. The zipsplit comes with the Zip package that allows you to easily split a Zip file into a set of smaller Zip files.
To split a Zip file of 24MB size into a 4MB file, run the following command.
zipsplit -n 4096000 bigfile.zip
This command splits the bigfile.zip into six files with a size 4MB of each.
To Unzip a password protected Zip file, you need to provide a password to extract the Zip archive. Run the following command to Unzip a password protected Zip file.
unzip protected1.zip
This prompts you to provide a password to extract the Zip file as shown below.
You can also use the -P option to provide a password with Unzip command.
unzip -P yourpassword protected1.zip
Now, your protected Zip file will be extracted without asking you a password.
Thank you for reading How to Zip and Unzip Files in Linux Terminal. We shall conclude this article now.
How to Zip and Unzip Files in Linux Terminal Conclusion
In this post, we have explained how to Zip and Unzip a file in a Linux terminal. We also used different options with Zip and Unzip commands and showed you real life examples. I hope this guide assists you to Zip and Unzip a file in your day to day tasks. Overall, the Zip utility is a handy tool to reduce the file and directory size and transfer them easily to your friends and other systems.
Do explore more of our Ubuntu content by navigating to this section of our blog.
I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.
00votes
Article Rating
Subscribe
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.
DisagreeAgree
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.