Linux Terminal Command: gzip
The gzip command is an essential tool in File Manipulation & Viewing. In this tutorial, we will explore what gzip does, look at everyday examples, and cover advanced options to supercharge your command-line workflow.
Concept & Explanation
The gzip command compresses files using the Lempel-Ziv coding (LZ77). By default, it replaces the original file with a compressed version ending in .gz.
Common Options & Syntax
gzip [options] [arguments]
Here are the most common flags used with gzip:
- Simple Usage: Basic default commands.
- Detailed View: Shows diagnostic information.
- Advanced Actions: Can chain parameters for scripting.
1. Interactive Example (Simple)
Here is how most people run the command:
# Example
gzip logs.txt
What it does: Compresses ’logs.txt’ into ’logs.txt.gz’ and deletes the original file.
2. Power-User Example (Advanced)
For scripting and advanced diagnostics, use this configuration:
# Advanced
gzip -dk9 backup.sql
What it does: Decompresses (-d) ‘backup.sql.gz’, preserves the original compressed file (-k), and uses maximum compression level 9 (-9).
⚙️ Warning & Common Pitfalls
[!WARNING]
gzipcan only compress individual files. It cannot bundle multiple folders. Usetarto archive files first, then compress it.
🔗 Related Commands
Here are some related posts on cli_tty1 you might want to check out:
- tar : Tape archiver utility.