How To Create A Zip File In Linux?
This post was last updated on August 1st, 2020 at 12:29 pm
Zip is an archive file format that supports lossless data compression. Zipping and unzipping tools are available for various platforms. Windows and macOS and many other OS are providing built-in zip support. These files generally use
.ZIP file extension. A zip tool allows you to specify the compression level from 1 to 9. Ahead in this article, we will discuss creating a zip file in Linux.
- 1 How to install the zip tool?
- 2 How to create a Zip archive file in Linux?
How to install the zip tool?
As discussed above many operating systems provides built-in support for the zip file format. But it is possible that some Linux distributions do not have a pre-installed zip tool or command. If it is not installed in your system then install it by using the following command –
Debian Based Ubuntu, Linux Mint, etc:
If you are using a Debian based distribution such as Ubuntu, Linux Mint, etc. then use –
sudo apt-get install zip
RPM-based CentOS, RedHat Linux, etc:
If you are using a system that uses yum package manager then use –
sudo yum install zip
To install it in fedora use –
sudo dnf install zip
How to create a Zip archive file in Linux?
The syntax of zip command is given below –
zip [options] file.zip file(s)
Creating a zip archive from a directory –
To create a zip archive of a directory named sample which contains some file and directories inside it, use the following command in your terminal –
zip -r sample.zip sample
Now a file named sample.zip will be created inside the current working directory.
Creating zip archive from files
Suppose you have different files in your current working directory then you can create a zip archive of these files by using the following command –
zip myzipfile.zip file(s)
For example –
zip myzipfile hello.txt hello1.txt hello2.txt hello3.txt
This will create an archive named myzipfile.zip in the current working directory.
Creating a zip archive of all text files in the current working directory –
Use the following command –
zip myzipfile *.txt
Deleting original files or directories after creating a zip archive –
If you want to delete the original file after creating a zip archive then you need to use
-m option with zip command –
For example –
zip -r -m sample.zip sample
Here target directory named sample will be deleted automatically after sample.zip is created.
There are many options available that you can use with the zip command. Run the zip command without any arguments to display the options –
You might also like
This post was last updated on August 1st, 2020 at 09:56 pmIn the context of the Linux operating system, PPA stands for “personal package archive”. By using PPA anyone can
This post was last updated on August 2nd, 2020 at 01:35 pmThe apt-fast is a shell script wrapper for apt-get and aptitude that can drastically improve the downloading speed of
This post was last updated on August 1st, 2020 at 12:20 pmDifferent Linux distribution comes with different tools to manage software packages on it. RPM-based Linux distributions such as CentOS,