🗜️ gzip Command Cheat Sheet (Linux)

🗜️ gzip Command Cheat Sheet (Linux)
Operating System(s)

The gzip command in Linux is used to compress and decompress files quickly. It’s commonly used to reduce file size for storage, backups, and faster transfers.

⚡ Quick Overview

CommandPurpose
gzip fileCompress a file
gunzip file.gzDecompress a file
gzip -k fileKeep original file
gzip -d file.gzDecompress (same as gunzip)

📦 Compress Files

Basic Compression

gzip file.txt

👉 Replaces file.txt with file.txt.gz

Keep Original File

gzip -k file.txt

👉 Keeps both original and compressed file

Compress Multiple Files

gzip file1.txt file2.txt

📤 Decompress Files

Using gunzip

gunzip file.txt.gz

Using gzip

gzip -d file.txt.gz

📂 Compress Folders (Important)

gzip cannot compress folders directly. (more information on tar)
👉 Use tar + gzip:

tar -czvf archive.tar.gz folder/

🔍 View Contents Without Extracting

zcat file.txt.gz

👉 Prints file contents to terminal

⚙️ Useful Options

OptionDescription
-kKeep original file
-dDecompress
-lList file info
-rRecursive (compress directories)
-1 to -9Compression level (fast → best)

🚀 Real-World Examples

Compress logs

gzip logfile.log

Compress with max compression

gzip -9 largefile.txt

View compressed file

zcat logfile.log.gz

Combine with grep (more information on grep)

zcat logfile.gz | grep error

👉 Search inside compressed logs without extracting

⚠️ Common Mistakes

  • ❌ Trying to compress folders directly
  • ❌ Forgetting it deletes original file
  • ❌ Using wrong tool (zip vs gzip)

🧠 Pro Tips

  • Use -9 for maximum compression
  • Use zcat instead of extracting large logs
  • Combine with tar for backups
  • Use gzip -k to avoid losing originals

👍 Quick Summary

  • gzip compresses files into .gz
  • gunzip or -d decompresses
  • Works on files, not folders
  • Often used with tar

🎯 Final Thoughts

The gzip command is fast, efficient, and widely used across Linux systems. Once combined with tar, it becomes one of the most powerful tools for backups and file management.

Force Cache (Faster Mirror)

Linux Commands

Files

tar · pv · cat · tac · chmod · grep ·  diff · sed · ar · man · pushd · popd · fsck · testdisk · seq · fd · pandoc · cd · $PATH · awk · join · jq · fold · uniq · journalctl · tail · stat · ls · fstab · echo · less · chgrp · chown · rev · look · strings · type · rename · zip · unzip · mount · umount · install · fdisk · mkfs · rm · rmdir · rsync · df · gpg · vi · nano · mkdir · du · ln · patch · convert · rclone · shred · srm · scp · gzip · chattr · cut · find · umask · wc · tr · hash  · compgen

Processes

alias · screen · top · nice · renice · progress · strace · systemd · tmux · chsh · history · at · batch · free · which · dmesg · chfn · usermod · ps · chroot · xargs · tty · pinky · lsof · vmstat · timeout · wall · yes · kill · sleep · sudo · su · time · groupadd · usermod · groups · lshw · shutdown · reboot · halt · poweroff · passwd · lscpu · crontab · date · bg · fg · pidof · nohup · pmap

Networking

netstat · ping · traceroute · ip · ss · whois · fail2ban · bmon · dig · finger · nmap · ftp · curl · wget · who · whoami ·· iptables · ssh-keygen · ufw · arping · firewalld