Online Linux Terminal Logo
OnlineLinuxTerminal
Archives & CompressionCLI Reference

$gzip

Compress or expand files using Lempel-Ziv coding (LZ77).

Syntax DefinitionPOSIX standard
gzip [OPTIONS] [FILE...]
Linux Community2.4k Online

Chat with real Linux users, learn new commands & get free cheat sheet PDFs.

Try `gzip` Live in Interactive Sandbox

Zero-install client simulation with real-time feedback.

Open in Fullscreen Workspace↗
bash — terminal

Overview & How gzip Works

`gzip` compresses individual files, replacing them with `.gz` extensions. It is the standard compression format across Linux for package distribution, web compression, and system log archiving.

Common Flags & Command Options

Flag / OptionDescription
-d, --decompressDecompress files (same as gunzip).
-k, --keepKeep (do not delete) original input files during compression.
-9, --bestUse maximum compression ratio (slower).

Practical Real-World Examples

Example #1Compress a log file
gzip -k notes.txt && ls -l notes.txt*

Compresses notes.txt to notes.txt.gz while preserving original notes.txt.

Sample Output:
-rw-r--r-- 1 user user 1200 notes.txt -rw-r--r-- 1 user user 420 notes.txt.gz

Frequently Asked Questions

Can gzip compress a directory directly without tar?

No, `gzip` only compresses individual files. To compress a whole folder, bundle it first with `tar` (producing a `.tar.gz`).