How To Zip Folder In Linux: A Step‑by‑Step Guide

If you’re wondering how to zip a folder in Linux, you’ve come to the right place. Whether you need to compress a project directory for backup, share files with a colleague, or simply free up disk space, the zip command line utility makes the job quick and reliable. In this tutorial you will learn two common methods: using the built‑in zip tool and using tar with gzip compression.

Why Use Zip on Linux?

Zip archives are widely supported across operating systems, including Windows and macOS. This compatibility means a zip file created on a Linux server can be opened on virtually any computer without extra software. Additionally, zip supports password protection and file‑level compression, giving you flexibility for both personal and professional use.

Method 1 – Zip a Folder with the zip Command

Install the zip package (if needed)

Most modern distributions ship with zip pre‑installed. To verify, run:

zip -v

If the command is not found, install it using your package manager:

Basic syntax

To zip a folder named myproject and create myproject.zip, run:

zip -r myproject.zip myproject

The -r flag tells zip to recurse into subdirectories, ensuring every file inside the folder is included.

Adding compression level and password

If you want maximum compression, add the -9 option:

zip -r9 myproject.zip myproject

To protect the archive with a password, use -e (you will be prompted for the password):

zip -re myproject.zip myproject

Excluding files or directories

Sometimes you need to skip temporary files, logs, or version‑control folders. Use the -x option followed by a pattern:

zip -r myproject.zip myproject -x "*.log" "myproject/.git/*"

Method 2 – Create a Gzipped Tar Archive (tar.gz)

When to choose tar.gz

Tar archives preserve file permissions and symbolic links, which can be important for system backups. While the resulting file has a .tar.gz extension, most graphical archive managers treat it the same as a zip file.

Creating the archive

Run the following command to compress the folder myproject into myproject.tar.gz:

tar -czvf myproject.tar.gz myproject

The flags mean: