Skip to content

How to Zip and Unzip Files in Linux (and Extract to a Specific Directory)

Updated 2 min read

Updated: 30 September 2026 · Applies to: zip and unzip on Ubuntu 24.04, Debian 13, AlmaLinux and Rocky Linux 9

zip and unzip create and open .zip files, the format Windows and macOS use too. We tested every command on Ubuntu 24.04 and AlmaLinux 9.

Install

sudo apt install zip unzip      # Ubuntu, Debian
sudo dnf install zip unzip      # AlmaLinux, Rocky Linux

Create a zip file

zip archive.zip file1.txt file2.txt     # some files
zip -r site.zip public_html             # a folder with everything in it
zip -r site.zip public_html -x "*.log"  # leave out log files

Unzip

unzip site.zip                  # into the current folder
unzip site.zip -d /tmp/restore  # into another folder (created if missing)
unzip -l site.zip               # list the contents without extracting
unzip -o site.zip               # overwrite existing files without asking
unzip site.zip "public_html/wp-config.php"   # just one file

Password-protected zip files

See how to create a password-protected zip file; 7z gives stronger AES encryption than classic zip.

Zip or tar?

Use zip when the file goes to Windows or macOS users. For backups on Linux servers, tar.gz keeps file owners and permissions: see how to extract a tar file to a specific directory.

In cPanel

In File Manager, select files and click Compress, or select a zip file and click Extract.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Linux server management

hardening, patching, monitoring and automation for Ubuntu, Debian, RHEL and AlmaLinux.

Was this answer helpful?

Still stuck? Open a ticket