Session and utilities

The gzip command

Compresses a file with the gzip algorithm and adds the .gz extension. It is the de facto standard on Linux.

Syntax

gzip [-d] [-k] [-c] archivo

Most useful options

-dDecompresses (same as gunzip)
-kKeeps the original file
-cWrites to screen without touching the file
-lLists the compression ratio

Copy-ready examples

$ printf 'texto de prueba\n' > f.txt && gzip -k f.txt && lsCompress keeping the original

You can try them in the browser terminal: it does not touch your computer.

Typical mistakes

  • Without -k, gzip deletes the original and leaves only the .gz.
  • gzip only compresses files, not folders: for that use tar.

Related commands

FAQ

Can I compress several files at once?

gzip creates one .gz per file; to bundle them into one use tar -czf.

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course