Overview¶
Linux provides powerful tools to archive and compress files/directories. The most commonly used utilities are:
-
tar→ Create and extract archive files -
gzip→ Compress files using gzip format
These tools are widely used for:
-
Backups
-
File transfer
-
Log storage
-
Packaging projects
tar — Archive Utility¶
Description¶
tar (Tape Archive) is used to combine multiple files and directories into a single archive file.
-
Archive format:
.tar -
Does not compress by default
Basic Syntax¶
Create Archive¶
Explanation¶
-
-c→ create archive -
-f→ specify archive file name -
File/→ directory or file to archive
Create Archive with Verbose Output¶
Explanation¶
-v→ verbose (shows files being processed)
Example Output¶
Extract Archive¶
Explanation¶
-
-x→ extract archive -
-v→ verbose output -
-f→ archive file
Extract to Specific Directory¶
Explanation
Extracts contents into a specified location.
gzip — Compression Utility¶
Description¶
gzip is used to compress files and reduce size.
-
Common format:
.gz -
Often combined with
tarto create.tar.gz
Create Compressed Archive (.tar.gz)¶
Explanation¶
-
-c→ create archive -
-z→ compress using gzip -
-f→ specify file name
Create with Verbose Output¶
Extract .tar.gz Archive¶
Explanation¶
-
-x→ extract -
-z→ decompress gzip -
-f→ file name
Extract with Verbose Output¶
Extract to Specific Directory¶
Common tar Options Summary¶
| Option | Meaning |
|---|---|
-c |
Create archive |
-x |
Extract archive |
-f |
Specify file name |
-v |
Verbose output |
-z |
Use gzip compression |
Practical Examples¶
Example 1: Archive a Folder¶
Example 2: Compress a Folder¶
Example 3: Extract Archive¶
Example 4: Extract Compressed Archive¶
tar vs gzip¶
| Feature | tar | gzip |
|---|---|---|
| Purpose | Archive files | Compress files |
| Output | .tar |
.gz |
| Compression | No | Yes |
| Usage Together | Yes (.tar.gz) |
Common |
Important Notes¶
-
taronly archives, not compresses (unless-zis used) -
.tar.gzis widely used for backups and distribution -
Always verify archive contents before extraction
-
Use
-vfor debugging and visibility
Summary Table¶
| Command | Purpose |
|---|---|
tar -cf |
Create archive |
tar -cvf |
Create archive with details |
tar -xvf |
Extract archive |
tar -czf |
Create compressed archive |
tar -xzf |
Extract compressed archive |
Conclusion¶
The tar and gzip utilities are essential for:
-
Managing backups
-
Reducing file sizes
-
Transferring data efficiently
Mastering these commands enables efficient file handling in Linux environments, especially in system administration and cybersecurity workflows.