How To Create A Zip File In Linux?

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 or .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.

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

For Fedora:

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 –

zip

That’s all for now. You may also read how to create a password-protected zip file or how to extract a zip file.

Previous How To Upgrade To Ubuntu 20.04 LTS From Ubuntu 18.04 Or Ubuntu 19.10?
Next How To Extract A Zip File In Linux Using Terminal?
 

About author

You might also like

Linux Topics 0 Comments

What Is PPA And How To Add Or Remove It In Ubuntu Using Command Line?

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

Linux Topics 0 Comments

What Is apt-fast And Why Should You Use It?

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

How To 0 Comments

How To Remove/Uninstall Software packages from CentOS, RHEL, Fedora?

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,

0 Comments

No Comments Yet!

You can be first to comment this post!

Leave a Reply