zip is a command-line archiving and compression tool. It bundles files and folders into a single .zip file, shrinking them with lossless compression along the way. Nothing is lost — you get the exact bytes back on extraction.
The reason I still reach for ZIP instead of tar.gz on certain jobs is simple: compatibility. A Windows user can double-click it. A macOS user can double-click it. No explaining what a tarball is. That makes it the format of choice for backups you'll hand off, client deliverables, and anything crossing operating systems.
The most popular lossless data compression archive file format is Zip. A Zip file is a data object that encapsulates one or more compressed files and folders. Uncompressed files take up more disc space and take longer to transmit from one device to another. Zip files may be readily extracted on Microsoft Windows, macOS, and Linux operating systems using the appropriate software for each platform. In this guide, you'll learn how to use the zip command in Linux with examples [ZIP File Linux/Zip Folder Linux] to compress files and directories. If you're coming from a desktop distro and want the GUI equivalent, see how to zip files and folders in Ubuntu instead.

🔍 What is Zip Command?
In this section, we'll delve into a detailed explanation of the Zip command in Linux and its multifaceted role in computing. Zip isn't just a file compression tool; it's a versatile utility that serves as a compression engine and a file packaging solution.
- Versatile Utility: Zip is a versatile tool that serves a dual purpose. It functions not only as a compression tool but also as a sophisticated file packaging utility.
- Compression Function: At its core, Zip is designed to compress files and directories, reducing their size significantly. This compression feature is essential for efficient storage and transmission of data, particularly when dealing with large files or limited bandwidth connections. Ready to Optimize Your Website's Load Time? Try Compressing Your .jpeg and .png Images Now!
- File Packaging: Beyond compression, Zip excels at packaging files and directories into a single .zip archive. This archive contains the compressed data and essential metadata about each encapsulated file. This metadata includes file names, paths, dates of last modification, protection settings, and even checks to verify file integrity.
- Cross-Platform Compatibility: Zip's versatility extends to its cross-platform compatibility. It's not confined to a particular operating system; instead, it's available on a wide range of platforms, including Unix, Linux, Windows, and more. This cross-compatibility empowers users to work seamlessly with Zip archives regardless of the operating system they're using.
- Broad Applicability: Zip's wide-reaching compatibility and functionality make it a valuable tool for various tasks. Whether you need to conserve disk space, distribute files efficiently, or streamline data transfers, Zip provides a robust and flexible solution.
📥 How to Install zip and unzip on Linux
Most minimal server images ship without it. Install both tools at once — you'll want the extraction side too.
Ubuntu and Debian:
sudo apt update && sudo apt install zip unzipCentOS, RHEL, AlmaLinux, Rocky Linux:
sudo dnf install zip unzipOn older CentOS 7 boxes, swap dnf for yum. If you're specifically on CentOS 7, our guide on how to zip and unzip files in CentOS 7 walks through the yum-based install in detail. Fedora uses the same dnf command. Arch Linux:
sudo pacman -S zip unzipVerify it worked:
zip -v
unzip -vBoth print version and build info. If you get a version string, you're set.
📝 zip Command Syntax
zip [options] archive.zip file1 file2 directory/Three parts. archive.zip is the output file you're creating (the .zip extension is added automatically if you leave it off). Everything after it is the input — files, folders, wildcards. Options go before or after, and control recursion, exclusion, encryption, and compression level.
📦 How to Compress Files and Directories in Linux [zip file and folder in Linux]
To zip file/folder with the zip command in Linux, you have to divide the files to be included in the pack by a space, as demonstrated below:
zip xyz.zip file1 file2 file3Output:
adding: file1 (deflated 53%)
adding: file2 (stored 0%)
adding: file3 (deflated 48%)The zip command in Linux publishes the names of the files that have been added to the archive as well as the compression technique by default. Unless the file that has to be compressed contains a .zip extension, the extension is created automatically if the archive name does not conclude with it.
zip xyz.zip file1 will produce the same archive as zip xyz file1. If you don't have a file handy to test with, you can always create files in Linux first.
- Use the -q option to suppress the output of the zip command in Linux:
zip -q xyz.zip file1 file2 file3Creating a zip archive of a directory that includes the content of subdirectories is common.
- You may recursively scan the full directory tree using the -r option:
zip -r xyz.zip dir1- In the same zip file linux, you can also add numerous files and directories:
zip -r xyz.zip dir1 dir2 filename1 filename2Now the one everybody actually searches for — how to zip a folder in Linux. You need -r for recursion, otherwise zip stores an empty directory entry and moves on:
zip -r project.zip project/Output looks like adding: project/index.php (deflated 62%) line by line. That percentage tells you how well each file compressed.

⚙️ Most Useful zip Command Options
| Option | What it does | Example |
-r |
Recurse into directories | zip -r backup.zip website/ |
-q |
Quiet mode — no per-file output | zip -q archive.zip file1 file2 |
-9 |
Maximum compression, slowest | zip -9 -r max.zip project/ |
-0 |
Store only, no compression | zip -0 logs.zip *.log |
-x |
Exclude matching patterns | zip -r p.zip project/ -x "*.log" |
-u |
Update only changed/new files | zip -u backup.zip config.php |
-d |
Delete an entry from an archive | zip -d backup.zip old-file.txt |
-m |
Move files in, deleting originals | zip -m archive.zip report.pdf |
-v |
Verbose output and progress | zip -v archive.zip file1.txt |
-T |
Test the archive after writing | zip -rT backup.zip site/ |
Options in Zip Command in Linux (Detailed)
- -d (Remove files from the archive): The -d option allows you to selectively remove specific files from an existing zip archive. After creating a zip file, you can employ this option to remove files of your choice using the following syntax:
zip -d [file_name.zip] [files_name]- -u (Update files in the archive): With the -u option, you can seamlessly update files within an already existing zip archive. This feature is particularly handy when you need to add new files or replace existing ones. The update process takes place only if the modified version of a file is more recent than the one already residing in the zip archive. The syntax for updating files is as follows:
zip -u [file_name.zip] [files_name]- -m (Move files into the archive): The -m option not only adds specified files to the zip archive but also moves them into the archive. Additionally, it deletes the source files or directories after successfully creating the zip archive. If a directory becomes empty due to the removal of files, it is also deleted. However, it's important to exercise caution when using this option, as it results in the permanent removal of input files. The syntax for moving files into the archive is as follows:
zip -m [file_name.zip] [files_name]- -r (Recursively zip a directory): The -r option is a powerful tool for recursively zipping an entire directory and all of its files. It includes all the files present in the specified directory and its subdirectories in the resulting zip archive. This option is incredibly useful when you need to create comprehensive zip archives containing an entire directory structure. The syntax for recursively zipping a directory is as follows:
zip -r [file_name.zip] [directory_name]- -x (Exclude files from the zip): The -x option offers precise control over the contents of your zip archive. You can use this option to exclude specific files from being included in the archive. This proves handy when you want to zip all files in a directory but wish to exclude certain unwanted files. The syntax for excluding files from the zip archive is as follows:
zip -r [file_name.zip] -x [directory_name]- -v (Verbose mode): When you need diagnostic information during compression, the -v option comes into play. It enables the verbose mode, providing a wealth of details about the zip file structure, compression progress, and the zip executable's information. You can even employ it to gain insights into your target environment. If used alone, it prints a diagnostic screen, offering comprehensive information about the zip operation. The syntax for enabling the verbose mode is as follows:
zip -v [file_name.zip] [file_name]A warning about -m: it deletes the source files once they're safely inside. If the archive is corrupted or the disk fills mid-write, you've got a problem. I use it rarely, and never on anything I can't regenerate.
-u is the one people misunderstand. It doesn't rebuild the archive — it only replaces entries whose timestamps are newer, and adds files that weren't there before. Great for incremental nightly backups. There's also -f (freshen), which updates existing entries but refuses to add new ones.
Excluding files and folders properly
This trips up more people than any other flag. Quote your patterns, always — otherwise the shell expands the wildcard before zip ever sees it:
zip -r backup.zip project/ -x "*.log" "node_modules/*" ".git/*"The patterns match against paths as stored in the archive, so they need to include the leading directory when relevant. If node_modules/* doesn't work, try project/node_modules/*.
Hidden files and directory structure
With -r, dotfiles inside a directory are included automatically. But zip -r archive.zip * skips them, because the shell's * never matches names starting with a dot. Use zip -r archive.zip . instead to capture everything in the current folder.
Paths are stored relative to where you run the command. Run zip -r backup.zip /var/www/html and you'll get the full nested path baked in — usually not what you want. Better: cd /var/www && zip -r backup.zip html/. Use -j if you want to flatten everything into a single level with no directories at all.
🗜️ Compression Methods and Levels [Zip Compression]
Deflate is Zip's default compression algorithm. If a file cannot be compressed, the zip utility just puts it in the file as it is, instead of compressing it with the store method. The bzip2 compression algorithm is supported by the zip program in most Linux variants.
The default method is deflate at level 6 — a sane middle ground. Levels run -0 (store, no compression) through -9 (maximum). On text, config files, and source code, -9 can buy you a few extra percent. On JPEGs, MP4s, or already-gzipped files? Almost nothing, and you'll burn CPU for the privilege. That's when -0 makes sense: bundling without compressing.
Use the -Z option to select a compression method.
zip -r -Z bzip2 xyz.zip dir1Output:
adding: sub_dir/ (stored 0%)
adding: sub_dir/filename1 (bzipped 27%)
adding: sub_dir/filename2 (bzipped 68%)The zip command in Linux lets you define a compression level from 0 to 9 by providing a number preceded by a dash. The compression level is set to -6 by default. When -0 is used, all files are saved without compression. -9 forces the zip command in Linux to perform the best compression possible for all files.
For example, if you wanted to utilize compression level -9, you would type:
zip -9 -r xyz.zip dir1The zip operation becomes more CPU-intensive when the compression level is increased, and it takes longer to complete.
Some builds support bzip2 via zip -Z bzip2 -r archive.zip folder/. Better ratios, slower, and not every ZIP client can read it. Test before you send it to a client.
🔐 How to Create a Password-Protected ZIP file?
If you have sensitive data that has to be saved in the archive, use the -e option to encrypt it:
zip -e xyz.zip dir1The archive password must be entered and verified using the following command:
Enter password:
Verify password:The password you will be entering will not be seen on the screen. However, the next time you log in, make sure you remember your password.
You'll be prompted twice for a password. For a folder, combine it: zip -er secure.zip private/.
Real talk — legacy ZIP encryption is weak and crackable with off-the-shelf tools. AES-256 ZIP (via 7z) or GPG is the right call for anything genuinely sensitive. Use -e for casual protection, not for credentials or customer data.
✂️ How to Create a Split Zip File?
Assume you wish to upload the Zip archive to a file hosting provider with a 1GB upload restriction, and your Zip archive is 5GB in size.
To create a new split Zip file, use the -s option followed by size. k (kilobytes), m (megabytes), g (gigabytes), or t (terabytes) can be used as the multiplier.
zip -s 500m -r xyz.zip dirAfter a set hits the stated size limit, the operation above will keep producing new archives in it.
For oversized archives, split them into chunks:
zip -s 500m -r backup.zip large-folder/You get backup.z01, backup.z02, and a final backup.zip. Handy for email limits, flaky uploads, or FAT32 media. All parts must sit in the same directory to extract.
📂 How to Unzip ZIP Files in Linux
unzip archive.zip # extract into the current directory
unzip archive.zip -d extracted/ # extract into a specific folder
unzip -l archive.zip # list contents without extracting
unzip -o archive.zip # overwrite existing files, no prompts
unzip -t archive.zip # test integrity
unzip archive.zip -x "*.log" # skip files while extractingAlways run unzip -l first on an archive someone sent you. A "zip bomb" of 4,000 loose files dumped into your home directory is a bad afternoon. For richer metadata — compression method, permissions, timestamps — use zipinfo archive.zip.

⚠️ Common Errors and Fixes
- zip: command not found — the package isn't installed. Go back to the install section for your distro.
- Permission denied — you can't write to the target directory, or can't read the source files. Write the archive to a path you own, or prefix with
sudo. Our basic Linux commands cheat sheet covers permissions in depth. - Archive contains unwanted files — your exclude pattern didn't match. Check the stored paths with
unzip -land adjust. - Exclude pattern ignored — you forgot the quotes and the shell expanded it first.
- Cannot find zipfile directory on a split archive — one of the
.z01parts is missing or in another folder.
🆚 zip vs tar.gz vs gzip
ZIP compresses each file individually and stores them in one container — you can pull a single file out without unpacking everything. That independence costs you a bit of ratio.
tar.gz concatenates first, then compresses the whole stream, which usually produces a smaller file and preserves Unix ownership, permissions, and symlinks faithfully. That's why Linux backups and software releases lean on it. If you need the extraction side, our guide on how to extract tar.gz files in Linux covers every flag. gzip alone isn't an archiver at all — it compresses one file stream, which is exactly why it's paired with tar.
Rule of thumb I use: sharing with non-Linux people, ZIP. Server-side backups on a Linux VPS, tar.gz.
✅ Best Practices
cdinto the parent folder first so paths stay relative and clean.- Exclude
.git,node_modules, caches, and logs — they inflate archives fast. - Test anything large with
unzip -tbefore deleting the source. - Name archives with a date:
site-backup-2025-06-14.zip. - Don't lean on
-ealone for sensitive data. - Schedule recurring archives with a cron job instead of doing it by hand.
- If you're running this on production hardware, a Linux dedicated server gives you the I/O headroom to compress large archives without slowing everything else down.
🎯 Conclusion
The zip command in Linux may be used to build Zip archives [Zip files and Folders in Linux]. On a Linux operating system, the unzip command may also be used to decompress a ZIP file. We have seen how to zip various files and directories in this tutorial and various available options for using the zip command in Linux.
You now have the whole workflow: install the tools, create archives, control compression, exclude junk, encrypt, split, and extract with unzip. Master -r, -x, and unzip -d and you've covered maybe 90% of daily use. The rest you'll pick up as the situations come.
People also read: