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

How To 0 Comments

How To Dual Boot Ubuntu 20.04 LTS And Windows 10?

This post was last updated on August 1st, 2020 at 12:46 pmCanonical recently released the latest version of Ubuntu that is Ubuntu 20.04 LTS for desktop and servers. The LTS

Linux Topics 0 Comments

How To Find A File Or Directory Quickly In Linux/Unix?

This post was last updated on August 2nd, 2020 at 12:47 pmSearching a file manually in Linux or Unix can be a little bit challenging task especially for new users.

Linux Topics 0 Comments

How to check if a disk uses GPT or MBR in Linux?

In a computer, MBR and GPT are two ways of storing the partitioning information on a disk. The MBR is a legacy while GPT is a newer disk partitioning style

0 Comments

No Comments Yet!

You can be first to comment this post!

Leave a Reply