How to Zip a File on Linux
Linux offers several command-line tools for file compression. This guide covers zip, tar, gzip, and GUI methods.
Method 1: Using the zip Command
The zip command creates standard .zip files compatible with Windows and macOS.
Install zip (if not already installed)
# Debian / Ubuntu
sudo apt install zip
# Fedora / RHEL
sudo dnf install zip
# Arch Linux
sudo pacman -S zip
Create a zip archive
# Zip a single file
zip archive.zip myfile.txt
# Zip multiple files
zip archive.zip file1.txt file2.pdf file3.jpg
# Zip a directory (recursive)
zip -r archive.zip my-folder/
# Zip with password protection
zip -e -r secure.zip my-folder/
Verify your zip file
# List contents without extracting
unzip -l archive.zip
Method 2: Using tar + gzip
The tar command combined with gzip compression creates .tar.gz files, the most common archive format on Linux.
Create a .tar.gz archive
# Create a compressed tar archive
tar -czf archive.tar.gz file1.txt file2.txt
# Archive a directory
tar -czf archive.tar.gz my-folder/
# Archive multiple items
tar -czf archive.tar.gz file1.txt file2.txt my-folder/
The flags mean: -c (create), -z (gzip compression), -f (output file).
List contents of the archive
tar -tzf archive.tar.gz
When to use tar.gz vs zip: Use .zip when sharing with Windows/Mac users. Use .tar.gz for Linux backups and source code distribution, as it preserves Unix permissions and offers better compression.
Method 3: Using gzip (Single Files)
For compressing a single file, gzip is the simplest option.
# Compress a file (replaces original with .gz version)
gzip myfile.txt
# Keep the original file
gzip -k myfile.txt
# Maximum compression
gzip -9 myfile.txt
# Decompress
gunzip myfile.txt.gz
Method 4: Using a GUI File Manager
Most Linux desktop environments support creating archives through the file manager.
Select files in your file manager
Open Nautilus (GNOME), Dolphin (KDE), or Thunar (Xfce) and select the files you want to compress.
Right-click and choose Compress
Right-click the selected files and choose "Compress..." or "Create Archive".
Choose format and location
Select .zip as the format, choose a destination, name the archive, and click Create.
Quick Command Reference
| Task | Command |
|---|---|
| Zip a file | zip archive.zip file.txt |
| Zip a folder | zip -r archive.zip folder/ |
| Zip with password | zip -e archive.zip file.txt |
| Create tar.gz | tar -czf archive.tar.gz folder/ |
| Gzip a file | gzip file.txt |
| List zip contents | unzip -l archive.zip |
| List tar.gz contents | tar -tzf archive.tar.gz |
Last updated: March 2026