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
Set vi as the default editor in Ubuntu — a terminal opening the vim editor
How to Set vi (Vim) as the Default Editor in Ubuntu
June 8, 2026
rsync says ALL DONE but files are missing — a terminal showing ALL DONE next to an empty folder
rsync Says “ALL DONE” but Files Are Missing: How to Verify
June 8, 2026
Migrate a website to a new server with rsync — files copying from an old server to a new one over SSH
How to Migrate a Website to a New Server With rsync
June 8, 2026
Bun runtime — faster JS toolkit replacing npm in Laravel projects
How to Install Bun Runtime on Ubuntu (And Use It in a Laravel Project)
May 24, 2026
Tailscale mesh — peer-to-peer connections between devices, coordination server
How to Install Tailscale on Ubuntu (Zero-Config Mesh VPN for Self-Hosters)
May 24, 2026

You Might Also Like

Nginx 502 with recv() failed 104 connection reset — PHP-FPM timeout and memory tuning
Server Management

Fix Nginx ‘recv() failed (104: Connection reset by peer)’ with FastCGI

9 Min Read
Install PHP on Ubuntu — terminal with apt install php command and stylized elephant icon
Web Development

How to Install PHP on Ubuntu (22.04 & 24.04): Step-by-Step Guide

9 Min Read
Stop cron job output and the resulting email spam
Server Management

How to Stop Cron Output (and the Spam Emails)

5 Min Read
WordPress admin notice — four notice types shown at the top of the admin area
Web Development

How to Show Custom Notifications in the WordPress Dashboard

6 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?