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.

1

Install zip (if not already installed)

# Debian / Ubuntu

sudo apt install zip


# Fedora / RHEL

sudo dnf install zip


# Arch Linux

sudo pacman -S zip

2

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/

3

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.

1

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).

2

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.

1

Select files in your file manager

Open Nautilus (GNOME), Dolphin (KDE), or Thunar (Xfce) and select the files you want to compress.

2

Right-click and choose Compress

Right-click the selected files and choose "Compress..." or "Create Archive".

3

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 filezip archive.zip file.txt
Zip a folderzip -r archive.zip folder/
Zip with passwordzip -e archive.zip file.txt
Create tar.gztar -czf archive.tar.gz folder/
Gzip a filegzip file.txt
List zip contentsunzip -l archive.zip
List tar.gz contentstar -tzf archive.tar.gz

Last updated: March 2026