Everything You Need to Know About the Zip Command in Linux

zip command in linux

Table of Contents

Get up to 50% off now

Become a partner with CyberPanel and gain access to an incredible offer of up to 50% off on CyberPanel add-ons. Plus, as a partner, you’ll also benefit from comprehensive marketing support and a whole lot more. Join us on this journey today!

Linux provides the zip command to compress files into the ZIP format, which is the most widely used archive file format for packing files and directories. By compressing files into an archive, you save space and reduce network bandwidth usage. While the tape archive (tar) format is more prevalent on Linux systems, ZIP remains a popular choice as well.

Reducing file size through compression makes it easier to bundle several files together, which speeds up data transfer and storage. Most operating systems, including Windows, macOS, Linux, and Unix, support the Zip format, enabling you to pack and unpack files on various platforms.

In this guide, we’re breaking down “How to zip command in Linux”- Learn the basics to power user tricks and zip confidently.

What Is The Zip Command In Linux?

what is a zip command in Linux-guide-for-2025

The zip command in Linux is a simple yet very powerful command-line utility in Linux that lets you create archives of files and folders. It also offers a variety of features for managing those archives.

It’s mainly used for storage, sharing, and backup processes.

Basic Usage

A fundamental application of the z (or x) command is to compress files into an archive. For instance, we can create an archive named important-backup.tar.gz by compressing two text files with the following command:

Tech Delivered to Your Inbox!

Get exclusive access to all things tech-savvy, and be the first to receive 

the latest updates directly in your inbox.

$ zip important-backup.zip credentials.txt statement.txt<br>adding: credentials.txt (stored 0%)<br>adding: statement.txt (stored 0%)

How to Install Zip on Your Linux System

To make a .zip file (compressed and packaged) using the command line, you can use a command like the one below. The -r option allows for recursive reading of the directory’s file structure.

$ zip -r tecmint_files.zip tecmint_files

Basic Syntax of the Zip File Command in Linux

The fundamental structure of the Linux zip command is:

zip [options] zipfile files_list

In this structure:

  • options are any command-line options you wish to apply.
  • zipfile is the name of the zip file you intend to create.
  • files_list includes the files you want to compress.

For example, to compress a file called filename.txt into a zip file named myfile.zip, you would enter the command:

$ zip myfile.zip filename.txt

If the command to zip files in Linux is not present in your system, install it with:

sudoaptinstallzip

How to View Contents of a Zip File in Linux

At times, we may just want to quickly check the contents of an archive without extracting it. This can be done easily with the zipinfo and unzip commands, which are included with the zip installation.

To see the contents of an archive using zipinfo, simply run the command followed by the archive filename as the only argument:

zipinfo important-backup.zip<br>Archive: important-backup.zip<br>Zip file size: 347 bytes, number of entries: 2<br>-rw-r--r-- 3.0 unx 8 tx stor 21-May-03 11:22 credentials.txt<br>-rw-r--r-- 3.0 unx 5 tx stor 21-May-03 11:22 statement.txt<br>2 files, 13 bytes uncompressed, 13 bytes compressed: 0.0%

Similarly, we can use the unzip command to list the content of an archive directly:

$ unzip -l important-backup.zip
Archive:  important-backup.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        8  2021-05-03 11:22   credentials.txt
        5  2021-05-03 11:22   statement.txt
---------                     -------
       13                     2 files

Advanced Zip Command Options

Use the -j option to compress the file1.txt and file2.txt files without including the directory paths in the archive.

$ zip -j archive.zip /path/to/file1.txt /path/to/file2.txt

How To Zip Multiple Files And Folders

To compress all files and folders in the current directory, you can use the asterisk (*) instead of listing each file individually.

Enhance Your CyerPanel Experience Today!
Discover a world of enhanced features and show your support for our ongoing development with CyberPanel add-ons. Elevate your experience today!

zip allfiles.zip *

This command will create a zip file containing all the files and folders in the current directory, but it will not include files within those folders.

Useful Flags To Preview Zip Archives

The zip command can encrypt an archive by using the -e flag. When this flag is used, the command prompts for a password, which acts as the encryption key for the archive.

Let’s create and encrypt an archive file encrypted-backup.zip:

$ zip -e encrypted-backup.zip bank-accounts.txt credentials.txt<br>Enter password:<br>Verify password:<br>adding: bank-accounts.txt (stored 0%)<br>adding: credentials.txt (stored 0%)

With the flag -e, the command will now prompt us for a password that serves as the key for encryption.

If we now attempt to unzip the archive, it’ll ask for a password to unarchive it:

$ unzip encrypted-backup.zip<br>Archive: encrypted-backup.zip<br>[encrypted-backup.zip] bank-accounts.txt password:<br>

However, we can still list the content of an encrypted archive using tools like zipinfo and unzip without knowing the password:

$ zipinfo encrypted-backup.zip<br>Archive: encrypted-backup.zip<br>Length Date Time Name<br>--------- ---------- ----- ----<br>17 2021-05-03 11:49 bank-accounts.txt<br>8 2021-05-03 11:22 credentials.txt<br>--------- -------<br>25 2 files

As we can see, it doesn’t prompt us for the password when we attempt to read its content listing.

Conclusion: Becoming a Zip Command Power User

The zip command in Linux seems simple, but it’s very useful. It can be used for everything from basic file backups to advanced automation in scripts.

This guide will help you master this tool to save you time and help keep your system organized. So, when you experience a cluttered folder, just zip it and move on. Why transfer 100 files, when you can just zip one.

FAQ’s

1. What is the purpose of the zip command in Linux?
The zip file command in Linux is used to compress files and folders into a .zip archive. It is particularly useful for conserving space, facilitating file transfers, and organizing information.

2. How can I compress an entire folder in Linux?
To compress a folder and all its contents, use the –r option:

<br>zip -r foldername.zip your_folder/

3. Is it possible to add new files to an existing zip archive?
Yes! You can use the -u option to update the archive:

<br>zip -u archive.zip newfile.txt

4. How do I secure a zip file with a password in Linux?
Simply use the -e option:

<br>zip -e secure.zip file.txt

You will be asked to enter a password.

5. How can I extract a zip file to a specific directory?
To unzip a .zip file to a designated location:

<br>unzip archive.zip -d /desired/path/
Areeba Nauman
Areeba is a Content Writer with expertise in web content and social media, she can simplify complex concepts to engage diverse audiences. Fueled by creativity and driven by results, she brings a unique perspective and a keen attention to detail to every project she undertakes with her creativity and passion for delivering impactful content strategies for success. Let's connect on Linkedin: https://www.linkedin.com/in/areeba-bhatti/
Unlock Benefits

Become a Community Member

SIMPLIFY SETUP, MAXIMIZE EFFICIENCY!
Setting up CyberPanel is a breeze. We’ll handle the installation so you can concentrate on your website. Start now for a secure, stable, and blazing-fast performance!