🗜️ Compressing and Decompressing Files
Think of file compression like vacuum-packing your clothes before a trip. You reduce the space they take up, so it's easier to store or send. Similarly, compression reduces file size to save disk space or make it faster to transfer over the internet.
Using gzip and gunzip
gzip compresses a file. gunzip decompresses it back to the original file.
Example:
1. Suppose you have a file called report.txt.
This compresses report.txt into report.txt.gz. Your original report.txt is replaced by the compressed version (gzip deletes the original by default).
2. To decompress:
This restores the original report.txt.
Using zip and unzip
zip compresses files (and can combine multiple files into one archive). unzip extracts them.
Example:
1. Compress one or more files:
This creates archive.zip containing both files. Unlike gzip, your original files remain.
2. Decompress the archive:
This restores file1.txt and file2.txt.
Quick Comparison Table
| Tool | Compress Single File? | Keeps Original? | Can Compress Multiple Files? |
|---|---|---|---|
| gzip | Yes | No | Not directly |
| zip | Yes | Yes | Yes |
Real-life analogy
For gzip and gunzip: You can think of .gz like putting your clothes in a vacuum bag - small, tight, and ready to move. When you gunzip, it's like unzipping the vacuum bag and your clothes are back to normal. For zip and unzip: Think of .zip like a backpack - you can put many items (files) in one bag and carry them together. When you unzip, you take everything out individually.