Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

gzip, gunzip, zcat

Compress files to .gz (gzip), unpack them (gunzip), or read them without unpacking (zcat).

Niveau
RHCSA-examen
Groep
Archiveren en comprimeren
Root nodig
Nee
Pakket
gzip
Ook
gunzip, zcat, zgrep, zless

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

gzip FILE replaces FILE with a smaller FILE.gz. gunzip FILE.gz (same as gzip -d) brings the original back. gzip is fast and everywhere; it is the default compression for logs and for .tar.gz archives.

gzip compresses one file at a time. To pack a folder, use tar -czf.

Tools to work with .gz files without unpacking them: zcat (show), zless (page), zgrep (search), zdiff (compare).

Zo schrijf je het

gzip [OPTION]... [FILE]...
gunzip [OPTION]... [FILE]...
zcat [OPTION]... [FILE]...

Opties 19

Meest gebruikt

-d, --decompress
Decompress (same as gunzip).
-k, --keep
Keep the original file.
-c, --stdout
Write to the screen (stdout); keep the files.
-l, --list
Show the compressed and uncompressed size and the ratio.
-r, --recursive
Compress every file in the folders.
-t, --test
Test the compressed file (is it complete and not damaged?).
-v, --verbose
Show the name and the ratio of each file.
-q, --quiet
No warnings.
-f, --force
Overwrite existing files; also compress links and files with more names.
-1, --fast
Fastest compression (bigger file).
-9, --best
Best compression (slower). The default is -6.
-n, --no-name
Do not save (or restore) the original name and time.
-N, --name
Save (or restore) the original name and time.
-S, --suffix=suf
Use another ending instead of .gz.
--rsyncable
Make the output friendly for rsync (small changes = small transfers).
--synchronous
Write safely to disk (slower).
-h, --help
Show help.
-L, --license
Show the license.
-V, --version
Show the version.

Voorbeelden 12

$ als gewone gebruiker# als root (of met sudo)

  1. 1Compress a file

    gzip access.log
    ls access.log*
    access.log.gz

    The original is replaced by the .gz file.

  2. 2Decompress

    gunzip access.log.gz

    Same as gzip -d access.log.gz.

  3. 3Keep the original

    gzip -k database.sql

    You get database.sql and database.sql.gz.

  4. 4Read a compressed log without unpacking

    zcat /var/log/messages-20261018.gz | tail

    No temporary file, no extra space used.

  5. 5Search in compressed logs

    zgrep -i "failed password" /var/log/secure-*.gz

    Searches old rotated logs directly.

  6. 6See the compression ratio

    gzip -l backup.tar.gz

    Shows compressed size, original size and ratio.

  7. 7Test a file after a transfer

    gzip -t backup.sql.gz && echo OK

    Finds broken downloads or cut transfers.

  8. 8Compress a database dump on the fly

    pg_dump appdb | gzip -9 > appdb-$(date +%F).sql.gz

    The dump never touches the disk uncompressed.

  9. 9Restore a compressed dump directly

    gunzip -c appdb-2026-10-25.sql.gz | psql appdb

    -c writes to stdout, the file stays.

  10. 10Compress all old files in a folder

    find /srv/exports -name "*.csv" -mtime +7 -exec gzip {} \;

    Saves space for data you rarely read.

  11. 11Compress every file in a tree

    gzip -r /tmp/old-reports/

    Each file is compressed alone; folders stay.

  12. 12Faster compression with all CPU cores

    tar -cf - /data | pigz > data.tar.gz

    pigz is a parallel gzip; the output works with normal gunzip.

Let op

  • gzip deletes the original by default. Use -k or -c if you need it.
  • gzip does not pack folders into one file: use tar.
  • gzip on a file that is still being written (a live log) can lose data; let logrotate do it.

Tips om te onthouden

  • gzip = pack, gunzip = unpack, zcat/zgrep/zless = read packed files.
  • -k keep, -c to stdout, -l list, -t test.

Volledige handleiding

Deze pagina legt het commando uit in eenvoudige woorden. De originele handleiding heeft elk detail.

In je terminal: man gzip