How To Zip A File In Linux

You all must be aware of zip files that are very commonly available on the internet and all can recognize the zip files from kids to older people as the files are ended with a .zip extension. People who are new to the Linux operating system often ask how to zip a file in Linux or how to compress files in Linux. Don’t worry, we’re here to help you out.

Before we tell you “How to Zip a file in Linux“, here is a little introduction on Zip file. Zip files are mainly an archiving system that bunch one or more files into one place thus takes up much less space on the computer. Along with saving space, the zip file also saves enough time in software downloading and transferring e-mail with an attachment. Moreover, users can maintain privacy at the same time that requires them to first encrypt the files before protecting it with a password. So, the need and uses of a zip file is almost clear to all while these files can be extracted or decompressed to view the stored files separately.

how to zip a file in linux

Now coming to how to zip files in Linux, this compress tool is available for every operating system including windows and iOS, so Linux is not an exception here.

How to Zip a file in Linux

Like Windows has Winzip program to zip the files, Linux operating system too has both this zip and unzip program but those are not installed on the OS by default. In case, you need to use them on your Linux machine, first go for the installation process. So, before knowing how to zip a file in Linux, it is important to know how you can get that first.

How to install zip tool for Linux:

The tools zip and unzip is installed from the shell prompt. So, launch the terminal by going to Application> System tool > Terminal but ensure that you have rooted your system for this to work.

Now, if you are a Debian or Ubuntu Linux user, the command would be:

# apt-get install zip – for installing the zip program and

# apt-get install unzip- for installing the unzip program OR else

$ sudo apt-get install zip unzip –for installing both zip and unzip program together.

how to zip a file in linux

But, the command would be bit different if you are a Red Hat Linux, Fedora or CentOS Linux user. Yum command is needed then for installing and uninstalling the zip/unzip tool.


# yum install zip- for installing the zip program and

# yum install unzip- for installing the unzip program

how to zip a file in linux

Once you have successfully installed both the tool, next comes the process of zipping and unzipping a file in Linux. The process is explained here in detail.

How to zip file and directories in Linux:

To create a zip file just type:

$ zip data * 

It will create the archive after which all the files will be put in that current directory in compressed form. There is no need of adding any kind of .zip as it will be done automatically by the zip command.

In order to verify the newly created zip file, you can type: $ ls 

If you want to zip a complete directory that includes all the subdirectory in it, type:

$ zip -r data *

So, that’s all you need to know to handle zip files in Linux easily. The process is quite simple, just type the above-mentioned command and you will be aware of “how to zip a file in Linux“. If you are using a Linux-based laptop PC, then you should check out our post on ways to improve battery life on Linux laptops.