~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.gz

Explanation: 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 /document

Explanation: 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.txt

Explanation: Compresses file.txt into file.txt.gz.


Decompressing a .gz file


gunzip file.txt.gz

Explanation: 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.txt

Explanation: Compresses file.txt into file.txt.zst.


Decompressing a .tar.zst file using zstd


zstd -d filename.tar.zst

Explanation: 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.zst

Explanation: 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_folder

Explanation: 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