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.
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.
tar -xvzf user.admin.dorgul.tar.gzExplanation: Extracts the contents of a gzip-compressed tar archive.
tar -cvzf ./tar.gz /documentExplanation: Compresses the /document directory into a gzip-compressed archive named tar.gz.
gzip is a fast and widely-used compression tool. It works well with tar and produces files with the .gz extension.
gzip file.txtExplanation: Compresses file.txt into file.txt.gz.
gunzip file.txt.gzExplanation: Restores the original file.txt from the compressed .gz file.
Zstandard (zstd) is a modern compression algorithm developed by Facebook. It offers high compression ratios and fast performance, producing files with the .zst extension.
zstd file.txtExplanation: Compresses file.txt into file.txt.zst.
zstd -d filename.tar.zstExplanation: Decompresses a Zstandard-compressed tar file into its original .tar format.
tar -I zstd -xvf archive.tar.zstExplanation: Uses tar with Zstandard to extract the contents of archive.tar.zst.
unzip is a simple utility for extracting files from .zip archives. It's commonly used for downloaded packages and shared files.
unzip file.zip -d destination_folderExplanation: Extracts file.zip into the folder destination_folder.
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.