Compress and extract a zip archive on Ubuntu / Debian linux

→ Are you a new visitor? Please visit the page guidance for new visitors ←

Compress and extract a zip archive on Ubuntu / Debian linux

The zip command is one of the most popular archive types used on the internet, should be by default in all linux, Windows and MacOS distribution, however there are certain cases where this is not present. For example a bare installation of centos or debian for instance would not have the zip command installed by default, although Windows, Ubuntu and MacOS should have by default support for zip archives. In this article I thought of showing you really simple how to compress and extract a zip archive on Ubuntu / Debian linux.

Install and use zip and unzip on Ubuntu / Debian linux

There are no repositories required added, these should be in the default linux package installer ready to be installed, if this has not yet been installed. So for instance, on Debian and Ubuntu installations, you can easily run the command:

This will easily install the zip and unzip command for future usage.

Creating a zip archive on Debian / Ubuntu

The above command will create an archive called with the folder example-folder and all subfolder recursively. This is the basic usage when creating an archive. We are also using the -r flag for recursive.

Extract a zip archive on Debian / Ubuntu

Using the unzip command on a zip archive to extract the contents is again really easy, same as with creating the zip command.

However in this case we use the flag -x to execute the archive and extract the contents.

There are also other usage of this command, for instance you can view only the contents of the archive before extracting using the command:

The result will be similar to:

Extract specific file from a zip archive

In the above manner, once we know what the archive contains, we can easily extract only the files we need from the archive, for instance, say we only require the foo1 file from our zip archive, we would use:

It will only extract foo1 from our archive as requested.

These are only the basics that you can use with the zip and unzip command, there are other usage for them, like deleting or updating content directly in the archive or replacing a file from the archive.

Anyway, this tool is really powerful and fast and I highly recommend all of you to use this since its a cross-platform archive type file extension, available by default on all operating systems.

That’s it for today, will see you again tomorrow with a new tutorial.

  • intrr

    Doesn’t work.

    Package zip is not available, but is referred to by another package.

    This may mean that the package is missing, has been obsoleted, or

    is only available from another source

    E: Package ‘zip’ has no installation candidate

    • Please check your APT source list. Probably can run one command before all

      apt-get update

      then try to install it as normal.

Request an article ←