Learn how to compress and decompress files quickly on the command line using gzip. 16.11.2025 | reading time: 2 min On the Linux command line, gzip is the go-to tool to compress single files quickly and transparently; learn the basic workflow and why it remains useful for transfers, storage and scripting. Quick example Compress a sample file and inspect results with this short session: ```bash # create a 1M sample file fallocate -l 1M report.txt ls -lh report.txt -rw-r--r-- 1 user user 1.0M Sep 12 12:00 report.txt gzip report.txt # typical gzip output report.txt: 46.5% -- replaced with report.txt.gz ls -lh report.txt.gz -rw-r--r-- 1 user user 463K Sep 12 12:01 report.txt.gz ``` This sequence shows gzip replacing the original file with a .gz archive and reducing the on-disk size. Flags and behavior to remember Use `-c` to write compressed output to stdout, `-d` or `gunzip` to decompress, `-k` to keep the original file on GNU gzip, `-r` to recurse into directories and `-1`..`-9` to trade speed for compression; `gzip -l` lists compressed-file stats and avoid compressing already compressed data like JPEG or MP3 because it yields little benefit and wastes CPU. Combine and pipeline For archives, pair gzip with tar (for example `tar -czf archive.tar.gz folder/`) or stream compression with `tar -cf - folder/ | gzip > archive.tar.gz`; to transmit compressed data without creating a file use `gzip -c file | ssh host "cat > file.gz"` or `gzip -c file | nc host port` in automation and backups. Alternatives worth knowing If you need better compression at the cost of CPU time try xz or bzip2, and for faster decompression on large datasets consider zstd; choose based on the storage, CPU budget and compatibility constraints of your environment. Final thought gzip is simple, ubiquitous and ideal for many everyday compression tasks; explore its options, practice combining it with tar and scripting, and deepen your Linux skillset for professional credentials like CompTIA Linux+ or LPIC-1 with intensive exam preparation at bitsandbytes.academy. Join Bits & Bytes Academy First class LINUX exam preparation. utilities storage backup filesystem scripting