~2 min read • Updated Sep 13, 2025
Introduction
Linux offers powerful tools for file compression and extraction. Whether you're backing up data, transferring files, or organizing directories, mastering commands like tar, gzip, zstd, and unzip is essential. Below are practical examples and explanations for each.
1. Using tar
tar is a classic archiving tool in Linux. It bundles multiple files into a single archive and is often combined with compression tools like gzip or zstd.
Extracting a .tar.gz archive
tar -xvzf user.admin.dorgul.tar.gzExplanation: Extracts the contents of a gzip-compressed tar archive.
- -x: Extract files
- -v: Verbose output
- -z: Use gzip
- -f: Specify archive file
Creating a .tar.gz archive
tar -cvzf ./tar.gz /documentExplanation: Compresses the /document directory into a gzip-compressed archive named tar.gz.
2. Using gzip
gzip is a fast and widely-used compression tool. It works well with tar and produces files with the .gz extension.
Compressing a file with gzip
gzip file.txtExplanation: Compresses file.txt into file.txt.gz.
Decompressing a .gz file
gunzip file.txt.gzExplanation: Restores the original file.txt from the compressed .gz file.
3. Using zstd
Zstandard (zstd) is a modern compression algorithm developed by Facebook. It offers high compression ratios and fast performance, producing files with the .zst extension.
Compressing a file with zstd
zstd file.txtExplanation: Compresses file.txt into file.txt.zst.
Decompressing a .tar.zst file using zstd
zstd -d filename.tar.zstExplanation: Decompresses a Zstandard-compressed tar file into its original .tar format.
Extracting a .tar.zst archive using tar and zstd
tar -I zstd -xvf archive.tar.zstExplanation: Uses tar with Zstandard to extract the contents of archive.tar.zst.
4. Using unzip
unzip is a simple utility for extracting files from .zip archives. It's commonly used for downloaded packages and shared files.
Extracting a .zip archive to a specific folder
unzip file.zip -d destination_folderExplanation: Extracts file.zip into the folder destination_folder.
Conclusion
Whether you're working with .tar.gz, .tar.zst, .gz, or .zip files, Linux provides efficient tools for compression and extraction. Understanding these commands helps streamline workflows, automate backups, and manage data with precision.
Written & researched by Dr. Shahin Siami