How to Zip a Folder on Linux using the terminal

In this quick guide, we will show you how to zip a folder on Linux directly from the terminal.

Linux Zip Directory

There are many reasons why you might want to zip a directory on your Linux system. You might be creating a backup of a folder or simply bundling a directory up to transfer it over the internet.

If you have never heard of Zip, it is an incredibly popular archiving format that supports lossless data compression. While it doesn’t offer as great as a compression ratio as the 7z format, it is incredibly well supported. You will struggle to find an operating system that isn’t capable of uncompressing a zip archive.

Luckily, creating a zip archive out of your folders is a straightforward process, especially if you are using the terminal on Linux.

The zip package is all you need to zip files or directories on Linux. This is a common package that is either included or easy to install with almost any Linux distribution.

If you want a more in-depth tutorial, we have a guide that focuses on using the zip command and all of its functionality.

Zipping a Folder on Linux from the Command Line

Over the following steps, we will show you how to zip a directory on Linux from the terminal.

These steps should work on basically any Linux operating system you throw at it. The only steps that may differ are if you don’t have the zip package installed on your system.

Ensuring the Zip Package is Installed on Linux

1. To archive a directory using the Zip file format you will need to have the “zip” package installed on to your machine. While this is often pre-installed on some operating systems, this isn’t always the case.

The steps we are showing here will install the zip package on Debian-like systems such as Ubuntu.

This first step will update the package list cache by running the command below.

sudo apt update

2. Once the package list cache has been updated, we can install the zip package using the following command.

If you want to be able to uncompress your Zip file, you should also install the unzip package.

sudo apt install zip

Using the Terminal to Zip a Folder on Linux

3. Once you have the zip package installed, making a zip of a folder on Linux is straightforward.

All you need to do is use the “zip” command, the “-r” option followed by the archives filename, and then the directory you want to zip.

The most important inclusion here is the “-r” option. This option tells the zip package to compress the given path recursively. Basically, it will allow you to zip a folder and all of its content.

zip -r <FILENAME> <FOLDER>

4. To show you how this works, we will use the zip command in our Linux terminal to create a new archive called “pimylifeup.zip“. This archive will include our user’s entire home directory.

zip -r pimylifeup.zip /home/pimyubu

Below is a quick screenshot of the Zip being created for our entire home directory.

Zip a Folder in Linux

Conclusion

Hopefully, at this point, you will know how to zip a directory on Linux while using the terminal.

Knowing how to zip directories is great, as it is a solid way of archiving your folders. The format makes transferring your files from one place to another easy.

Please feel free to comment below if you need any help with trying to zip a folder on your system.

If you found this quick guide to be helpful, we recommend exploring some of our other Linux tutorials.

Leave a Reply

Your email address will not be published. Required fields are marked *