ZIP holds onto its spot as the most portable archive format despite TAR dominating most Linux setups. The format pairs well with files moving between Linux and Windows boxes without extra software on either side. This walkthrough covers two ways to build a Linux zip file: through terminal commands and through the file manager on your desktop.
Check If zip Is Installed on Your Linux System
Many distributions skip the zip utility by default. Run a version check first:
zip --version
A version number means the tool is ready. A command not found reply means you need to add it. Read more on how to fix command not found errors if other tools show the same response.
sudo apt install zip unzip
The unzip part handles extraction and pairs naturally with zip. Type your sudo password and let the install run.
Create a Linux Zip File With the zip Command
The general shape of the command looks like this:
zip <options> <zip file> <source file(s)>
Without flags, it builds a fresh archive. Flags change the behavior. A wider zip command reference covers every available switch.
Common zip Command Flags
| Flag | Type | What It Does |
|---|---|---|
-u / --update | Mode | Refresh and add new items. Builds an archive if none exists. |
-f / --freshen | Mode | Refresh items only, no new ones added. |
-d / --delete | Mode | Pick items inside an archive and drop them. |
-e / --encrypt | Option | Lock the archive with a password prompt. |
-R / --recurse-patterns | Option | Pack files down through folders. |
-sf / --show-files | Option | Print what the command would touch, then quit. |
-x / --exclude | Option | Leave out the named files. |
-<number> | Option | Set squeeze speed from 0 to 9. |
Build Your First Zip Archive
Start by creating five blank text files:
touch file{1..5}.txt
Now bundle them:
zip files file1.txt file2.txt file3.txt file4.txt file5.txt
The terminal prints each step and produces files.zip in your current folder.
List Contents Inside a Linux Zip File
The -sf option prints what sits inside an archive without extracting anything:
zip -sf files.zip
The output shows every file name and the archive structure.
Add Specific File Types Only
Wildcards let you grab one extension at a time:
zip files *.txt
The command pulls every TXT file in the current directory into the archive.
Zip a Whole Directory With Subfolders
The -r flag walks down through a folder tree:
zip -r files <directory>
The directory entry lands first, then its files follow. If the source folder is no longer needed, this guide on deleting a directory in Linux covers safe removal steps. For empty folders, the rmdir command handles the cleanup faster.
Remove Files From a Linux Zip Archive
Check what is inside the archive first with -sf, then pull a file out with -d:
zip -d files.zip file5.txt
The target file disappears while the rest of the archive stays untouched.
Password-Protect a Linux Zip File
The -e flag adds encryption to your archive:
zip -e <archive file> <files>
A prompt asks for your password before bundling starts. Password-protected ZIPs work well for sharing logs or configs over networks where SSH or HTTPS is not already in place. To pull files out later, check the unzip command guide.
Set the Compression Level
Numbers from 1 to 9 control how hard zip squeezes the data:
zip -5 files *.txt
The -1 flag runs the fastest pass with the lightest compression. The -9 flag squeezes the tightest but takes longer. Values in between sit somewhere on that curve.
Most of the gain happens by level 5. The jump from 5 to 9 trims only a few extra percentage points while CPU time climbs sharply.
Create a Linux Zip File From the Desktop
Prefer clicking? Open Files and go to your folder. Highlight the items you want, right-click, and pick Compress. Type a name, choose .zip from the dropdown, then click Create. The archive shows up in the same folder, ready to move or share. The same right-click menu works for tar.gz archives as well if you need the other format later.
FAQs
How do I create a zip file in the Linux terminal?
Run zip archive_name file1 file2 in your terminal. For folders, add the recursive flag: zip -r myfolder.zip foldername. The archive lands in your current working directory once the command finishes.
Why does my Linux system say “zip: command not found”?
The zip utility ships separately on most distributions. Install it with sudo apt install zip unzip on Debian or Ubuntu, or sudo dnf install zip unzip on Fedora and RHEL systems.
Can I password-protect a Linux zip file?
Yes. Add the -e flag like this: zip -e archive.zip files. The terminal asks for a password before bundling. Anyone trying to extract the archive must enter the same password to access the contents.
How do I zip a whole folder in Linux?
Use the -r flag for recursive packing: zip -r backup.zip myfolder. The command pulls every file and subfolder inside myfolder into backup.zip while keeping the original directory structure intact.
What is the difference between zip and tar in Linux?
ZIP compresses each file separately and works across Windows and Mac without extra tools. TAR groups files first, then compresses the bundle. TAR keeps Linux file permissions intact, while ZIP focuses on cross-platform sharing.