The gzip command 🤐

gzip compresses files (not directories).

(The g means GNU)

Compressing Files

gzip --best <file-to-compress>
  • The original file is NOT preserved.
    (After executing gzip, repetitive-file is gone. Only the compressed output, repetitive-file.gz remains.)
  • --best means best compression (but slowest to perform).
    There is also --fast. It means fastest to perform (but worst compression).
    There are intermediate options:
    -1 (--fast), -2, -3, -4, -5, -6 (default), -7, -8, -9 (--best)

I prefer to use --best in most scenarios. These articles are intended for future Anton’s reference. That’s why I included --best in this first example.

Others may not consider --best as the proper default. Use it at your own discretion.

Compressing Files (Preserve Original)

gzip --keep <file-to-compress>

--keep keeps the original file intact during compression, as the name implies.

Compressing Files (Specify Suffix)

gzip --suffix '.myPersonalSuffix' <file-to-compress>

Decompressing Files

gunzip <file-to-decompress>
  • The compressed file is NOT preserved.
    (After executing gzip, repetitive-file.gz is gone. Only the decompressed output, repetitive-file remains.)
  • You can also use gzip --decompress. I just prefer using gunzip.

Decompressing Files (Preserve Compressed File)

gunzip --keep <file-to-decompress>

You can use the --keep option with decompression, not just compression.

P.S. If not given files to compress/decompress, gzip will compress from STDIN and compress to STDOUT.

Opinions expressed in these articles do not represent those of my employer.