File compression and archiving utilities are essential tools in Linux (and Unix-like systems) for reducing file size and bundling multiple files into a single file for easier management and transfer. These tools are crucial for system administrators to efficiently manage storage space and facilitate the transfer of large sets of files. Compression reduces the size of files, making them easier to store and faster to transfer over networks. Archiving combines multiple files into a single file, simplifying file management and backup processes. This document provides an overview of some common tools used for these purposes, including their usage and benefits.
tar
is the standard tool, often combined with compression tools.gzip
, bzip2
, xz
, zstd
, and 7z
provide various levels of compression ratios and speeds.zip
and rar
are useful for creating archives compatible with non-Linux systems.Tool | Compression | Archiving | Speed | Compression Ratio | Cross-Platform | Notes |
---|---|---|---|---|---|---|
tar | No | Yes | Fast | N/A | Yes | Often combined with other compression tools |
gzip | Yes | No | Fast | Moderate | Yes | Commonly used with tar |
bzip2 | Yes | No | Moderate | High | Yes | Better compression than gzip |
xz | Yes | No | Slow | Very High | Yes | Best compression ratio |
zip | Yes | Yes | Fast | Moderate | Yes | Widely used, especially in Windows |
7z | Yes | Yes | Moderate | Very High | Yes | Supports multiple formats |
ar | No | Yes | Fast | N/A | No | Used for Debian packages |
rar | Yes | Yes | Moderate | High | Yes | Proprietary, not default on many distros |
zstd | Yes | No | Very Fast | High | Yes | Fast compression with good ratios |
tar -cvf archive.tar file1 file2 file3
tar -xvf archive.tar
gzip filename
gunzip filename.gz
tar
:
tar -czvf archive.tar.gz file1 file2
tar -xzvf archive.tar.gz
gzip
but generally provides better compression at the cost of speed.bzip2 filename
bunzip2 filename.bz2
tar
:
bzip2
compressed archive: tar -cjvf archive.tar.bz2 file1 file2
tar -xjvf archive.tar.bz2
gzip
and bzip2
.xz filename
unxz filename.xz
tar
:
xz
compressed archive: tar -cJvf archive.tar.xz file1 file2
tar -xJvf archive.tar.xz
zip archive.zip file1 file2
unzip archive.zip
7z
(7-Zip)7z a archive.7z file1 file2
7z x archive.7z
zip
and is flexible in handling multiple archive formats.rar
and unrar
rar a archive.rar file1 file2
unrar x archive.rar
ar
ar rcs archive.a file1 file2
ar x archive.a
zstd
(Zstandard)gzip
but with better ratios similar to bzip2
.zstd filename
unzstd filename.zst
tar
:
zstd
compressed archive: tar --zstd -cvf archive.tar.zst file1 file2
tar --zstd -xvf archive.tar.zst