GO KALI FREE
Compression Commands

gzip Linux Command

Compresses a single file using the gzip algorithm (replaces original with .gz).

What does gzip do?

Compresses a single file using the gzip algorithm (replaces original with .gz).

Syntax

gzip [options] filename

Practical example

gzip -9 largefile.txt

Questions about gzip

How do I compress a file with gzip?

Use `gzip filename` to compress a file. The original file is replaced with filename.gz and deleted.

How do I decompress a .gz file?

Use `gunzip filename.gz` or `gzip -d filename.gz` to decompress. The .gz file is removed and the original is restored.

How do I compress without deleting the original?

Use `gzip -k filename` to keep the original file. Without `-k`, gzip replaces the original with the compressed version.

How do I set compression level?

Use `gzip -1 filename` for fastest compression, or `gzip -9 filename` for best compression. Default is -6 (balanced).

How do I compress multiple files?

Use `gzip file1 file2 file3` to compress multiple files. Each file becomes a separate .gz file.

How do I see compression ratio?

Use `gzip -l filename.gz` to see the compression ratio, original size, and compressed size.

How do I compress a directory?

gzip compresses single files. Use `tar -czf archive.tar.gz directory/` to compress a directory.

How do I decompress to stdout?

Use `gzip -dc filename.gz` to decompress to stdout without deleting the .gz file. This is useful for piping.

Related Compression Commands

tar

Archives multiple files into a single tarball. Use -czf to compress with gzip.

gunzip

Decompresses a .gz file back to its original form.

7z

High-compression archiver supporting many formats (7z, zip, rar, tar, etc.).

bzip2

Compresses files using the bzip2 algorithm (better compression than gzip, slower).

unxz

Decompresses a .xz file back to its original form.

bunzip2

Decompresses a .bz2 file back to its original form.