Tar and Gzip Basics
Introduction to Linux Compression
Linux compression is a critical skill for efficient file management and storage optimization. Two fundamental tools in this domain are tar and gzip, which enable users to archive and compress files effectively.
Understanding Tar Command
Tar (Tape Archive) is a Linux utility used for creating and manipulating archive files. It consolidates multiple files into a single file without compression.
Basic Tar Operations
## Create a tar archive
tar -cvf archive.tar file1.txt file2.txt
## Extract tar archive
tar -xvf archive.tar
## List contents of tar archive
tar -tvf archive.tar
Gzip Compression Utility
Gzip is a compression tool that reduces file sizes, making storage and transmission more efficient.
Gzip Command Examples
## Compress a file
gzip file.txt
## Decompress a file
gzip -d file.txt.gz
## Compress and preserve original file
gzip -k file.txt
Combining Tar and Gzip
Operation |
Command |
Description |
Create compressed archive |
tar -czvf archive.tar.gz files/ |
Compress files with gzip |
Extract compressed archive |
tar -xzvf archive.tar.gz |
Extract gzipped tar archive |
graph LR
A[Original Files] --> B[Tar Archive]
B --> C[Gzip Compression]
C --> D[Compressed Archive]