How7o
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: How to Zip Multiple Files and Directories on Linux
Share
How7oHow7o
Font ResizerAa
  • OS
Search
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Follow US
© 2024–2026 How7o. All rights reserved.
How7o > Free Laravel, PHP, WordPress & Server Tutorials > Server Management > How to Zip Multiple Files and Directories on Linux
Server Management

How to Zip Multiple Files and Directories on Linux

how7o
By how7o
Last updated: May 22, 2026
5 Min Read
Zip multiple files and directories on Linux — zip -r command
SHARE

To zip multiple files and directories on Linux, run zip -r archive.zip file1 file2 dir1/. The -r flag tells zip to recurse into directories; without it, only top-level files are added. This guide covers the basic command, installation across distros, common flags (excludes, compression level, passwords), and when to reach for tar.gz instead.

Contents
  • TL;DR
  • Check zip is installed
  • Zip files
  • Zip a directory (recursive)
  • Mix files and directories
  • Exclude files with -x
  • Compression level
  • Verify and unzip
  • Frequently asked questions
  • Related guides
  • References

Last verified: 2026-05-17 on Ubuntu 22.04 and AlmaLinux 9 with zip 3.0. Originally published 2022-12-24, rewritten and updated 2026-05-17.

TL;DR

# Zip several files into one archive
zip myarchive.zip file1.txt file2.txt file3.txt

# Zip a directory and everything inside it (-r = recursive)
zip -r site.zip site/

# Mix files and directories
zip -r project.zip README.md src/ tests/ assets/

# With exclusions
zip -r site.zip site/ -x 'site/node_modules/*' 'site/.git/*'

Check zip is installed

Most Linux distros ship the zip utility by default. Confirm with:

which zip

If that prints nothing, install it. On Ubuntu / Debian:

sudo apt install zip

On AlmaLinux / Rocky / RHEL / Fedora:

sudo dnf install zip
zip files and directories on Linux — basic command, recursion, exclusions, compression level

Zip files

zip myarchive.zip file1.txt file2.txt file3.txt

The first argument is the archive name; everything after is what to put in it. The archive is created in the current directory.

Zip a directory (recursive)

Pass -r to recurse into directories:

zip -r site.zip site/

This packs everything under site/ (subdirectories, hidden files, the works) into site.zip. Without -r, zip only stores the top-level directory entry and skips its contents — a common gotcha.

Mix files and directories

zip -r project.zip README.md src/ tests/ package.json

Same command, list whatever you want to include after the archive name.

Exclude files with -x

zip -r site.zip site/ -x 'site/node_modules/*' 'site/.git/*' '*.log'

Each -x pattern is a glob. Quote them so the shell doesn’t expand them before zip sees them. Patterns match against the path inside the archive, not the working directory.

Compression level

The -0 through -9 flags control compression: 0 = store only (no compression, fastest), 6 = default, 9 = maximum (slowest):

# No compression — fast, no CPU
zip -0 -r snapshot.zip site/

# Maximum compression — slow, smallest file
zip -9 -r site-archive.zip site/

For pre-compressed content (JPEGs, MP4s, .gz files), -0 is usually faster and produces the same size — there’s nothing left to squeeze.

Verify and unzip

# List contents without extracting
unzip -l site.zip

# Extract everything to current directory
unzip site.zip

# Extract to a specific directory
unzip site.zip -d /tmp/restored/

Frequently asked questions

Should I use zip or tar.gz?

On Linux, tar.gz is the more idiomatic choice — better compression, preserves Unix permissions and symlinks correctly, and every distro ships it by default. Use zip when the archive is going to a Windows user (Windows opens .zip natively but needs a separate tool for .tar.gz), or when a specific tool/API requires .zip format (most cloud storage and email systems prefer .zip).

Does zip preserve Unix file permissions?

Partially — zip stores file modes in the archive, and unzip restores them on Linux. But .zip wasn’t designed for Unix-style permissions, so things like symlinks and ownership (UID/GID) don’t round-trip cleanly. For full fidelity (including symlinks), use tar.

How do I exclude files when zipping?

Use the -x flag with a glob pattern: zip -r site.zip site/ -x 'site/node_modules/*' 'site/.git/*' '*.log'. Multiple -x patterns are supported, and the patterns are evaluated relative to the current directory.

Can I create a password-protected zip?

Yes, with zip -e archive.zip files — you’ll be prompted for the password twice. Be aware: standard zip encryption (ZipCrypto) is weak and trivially crackable. For anything sensitive, use AES-encrypted zip with 7z (7z a -p -mhe=on archive.7z files) or encrypt the archive separately with gpg.

How do I see what’s inside a zip without extracting it?

unzip -l archive.zip lists contents with sizes and modification times. zipinfo archive.zip gives a more detailed view including permissions and compression method per file.

Related guides

  • How to List Network Devices on Linux
  • How to Install Docker on AlmaLinux
  • How to Check if Pure-FTPd Is Installed on Linux

References

Info-ZIP project (upstream): infozip.sourceforge.net. man zip on any Linux system with zip installed.

TAGGED:Bashconfiguration

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article JavaScript check Unicode character — regex, codePointAt, Unicode property escape How to Check if a JavaScript String Contains a Unicode Character
Next Article aaPanel domain and Let's Encrypt SSL setup — secure the control panel How to Access aaPanel with a Domain and Let’s Encrypt SSL
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

FacebookLike
XFollow
PinterestPin
InstagramFollow
Most Popular
Run Laravel queue workers with Supervisor
How to Run Laravel Queue Workers in Production with Supervisor
May 23, 2026
Nginx as a reverse proxy for a Node.js app on Ubuntu
How to Set Up Nginx as a Reverse Proxy for Node.js on Ubuntu
May 23, 2026
Install and configure Redis on Ubuntu for Laravel and WordPress
How to Install and Configure Redis on Ubuntu (for Laravel & WordPress)
May 23, 2026
Harden a fresh Ubuntu VPS with UFW, Fail2Ban, and SSH key auth
How to Harden a Fresh Ubuntu VPS: UFW + Fail2Ban + SSH Key Auth
May 23, 2026
Set up Let's Encrypt SSL with Certbot on Ubuntu
How to Set Up Let’s Encrypt SSL with Certbot on Ubuntu (Apache & Nginx)
May 23, 2026

You Might Also Like

Nginx subdirectory configuration with alias and PHP-FPM
Server Management

How to Configure Nginx for a Subdirectory

5 Min Read
Laravel .htaccess exclude .well-known for Let's Encrypt ACME challenge
Server Management

How to Exclude .well-known from Redirection for Let’s Encrypt in Laravel

8 Min Read
Transfer Discourse to a new server
Server Management

How to Transfer Discourse to a New Server on AlmaLinux (Backup + Restore, Step-by-Step)

9 Min Read
Safely remove MySQL binary log files to free disk space
Server Management

How to Safely Clean Up MySQL Binary Log Files

5 Min Read
How7o

We provide tips, tricks, and advice for improving websites and doing better search.

Tools

  • Age Calculator
  • Word Counter
  • Image Upscaler
  • Password Generator
  • QR Code Generator
  • See all tools→

Pranks

  • Fake Blue Screen Prank
  • Hacker Typer
  • Fake iMessage Generator
  • Windows XP Crash Prank
  • Windows 11 Update Prank
  • See all prank screens →

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service
  • Sitemap
© 2024–2026 How7o. All rights reserved.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?