Migrate to RunxBuild and earn up to $50 in hosting credit on your first deposit.

Calculate your savings
unxBuild

How to Unzip a File in Linux: unzip, tar, gunzip, and 7z

Sean

Platform Writer

Jul 05, 2026
4 min read

How to unzip a file in Linux: unzip for .zip, tar -xf for .tar.gz/.tar.bz2/.tar.xz, gunzip for .gz, 7z for .7z. The team that uses the right tool for the archive format has correct extraction.

How to Unzip a File in Linux: unzip, tar, gunzip, and 7z

Table of contents

unzip for .zip

# Install if needed
sudo apt install unzip

# Extract
unzip file.zip
# To specific directory
unzip file.zip -d /target/dir/
# List contents (no extract)
unzip -l file.zip

The team that uses unzip for .zip files has the standard tool.

tar for .tar.gz/.tar.bz2/.tar.xz

# .tar.gz
tar -xzf file.tar.gz
# .tar.bz2
tar -xjf file.tar.bz2
# .tar.xz
tar -xJf file.tar.xz

# To specific directory
tar -xzf file.tar.gz -C /target/dir/

# List contents
tar -tzf file.tar.gz

Flags: -x=extract, -z=gzip, -j=bzip2, -J=xz, -f=file, -t=list, -C=directory.

gunzip for .gz

# Decompresses in place (replaces .gz with original)
gunzip file.gz

# Keep original, write to stdout
gunzip -c file.gz > file

The team that uses gunzip for .gz files has the standard tool.

7z for .7z

# Install
sudo apt install p7zip-full

# Extract
7z x file.7z

The team that uses 7z for .7z archives has the right tool.

rar for .rar

# Install unar (universal extractor)
sudo apt install unar

# Extract
unar file.rar

The team that has .rar files (rare on Linux) uses unar for cross-format extraction.

Verify archive integrity

# tar with t flag
tar -tzf file.tar.gz | head

# Test integrity
gzip -t file.gz
unzip -t file.zip

The team that verifies has confidence the archive is intact.

FAQ

How do I unzip a .tar.gz?

tar -xzf file.tar.gz. The team that uses the right flags has correct extraction.

What’s the difference between zip and tar.gz?

Zip: Windows-friendly, single tool. tar.gz: Unix-friendly, higher compression. The team that picks based on use case.

Can I extract to a specific directory?

Yes - tar -xzf file.tar.gz -C /target/ or unzip file.zip -d /target/. The team that uses -C or -d has correct extraction path.

How do I extract a password-protected zip?

unzip -P password file.zip.

Why is the extracted file huge vs the archive?

Compression ratio depends on file type. Text compresses well. Already-compressed files (jpg, mp4) don’t. The team that expects 10x compression on text has realistic expectations.

If you are sizing the infrastructure for the kind of project this post covers, the RunxBuild hosting calculator is the right place to model the line items. The compute, the memory, the storage, the bandwidth, the database - each one is a separate number, and the team’s mental model for the platform is the sum of those numbers. The RunxBuild dashboard is where the team sees the actual usage in one place.

Useful related references:

#linux#unzip#tar#compression#dev-infra