Compress or decompress files using the GNU zip DEFLATE algorithm.
low risk
gzip compresses a single file and replaces it with a .gz version. -k keeps the original. -d decompresses (same as gunzip). Compression level -1 (fastest) through -9 (best ratio). Combine with tar for multi-file archives.
| Flag | Meaning |
|---|---|
-d --decompress | Decompress a .gz file (same as running gunzip) |
-k --keep | Keep the original file after compressing |
-c --stdout | Write output to stdout, don't replace file |
-r --recursive | Recursively compress all files in a directory |
-l --list | Show compression ratio and sizes for .gz files |
-1 --fast | Fastest compression, lowest ratio |
-9 --best | Best compression ratio, slowest speed |
-v --verbose | Show compression ratio for each file processed |
gzip -k -9 large_dump.sqlCompress SQL dump with best ratio, keeping the original file · explain & risk-check →gzip -d archive.gzDecompress a .gz file back to its original form · explain & risk-check →gzip -l *.gzShow compression stats (ratio, original vs compressed size) for all .gz files · explain & risk-check →Use `zcat file.gz | grep pattern` to search inside a compressed file without decompressing it to disk first.
Reference text is hand-written and may be incomplete — check man gzip for your version. Test destructive commands on a non-production system first.