2.6 Archiving and Compression
In Linux, “archiving” (bundling many files into one) and “compression” (making files smaller) are often two separate steps, though modern tools combine them.
Archiving with tar
Section titled “Archiving with tar”tar (Tape ARchive) is the standard tool for bundling files.
-
Create an archive (
-c):(Flags: create, verbose, file)
-
Extract an archive (
-x):(Flags: extract)
-
List contents (
-t):
Compression Tools
Section titled “Compression Tools”Linux supports multiple compression formats. gzip is the most common, while xz offers better compression at the cost of speed.
| Tool | Extension | Compress | Decompress |
|---|---|---|---|
gzip | .gz | gzip file | gunzip file.gz |
bzip2 | .bz2 | bzip2 file | bunzip2 file.bz2 |
xz | .xz | xz file | unxz file.xz |
zip | .zip | zip -r arch.zip dir | unzip arch.zip |
Combining with tar
Section titled “Combining with tar”You usually don’t compress distinct files; you compress a tarball.
-
gzip (
-z):archive.tar.gzor.tgz -
bzip2 (
-j):archive.tar.bz2 -
xz (
-J):archive.tar.xz
Backups with rsync
Section titled “Backups with rsync”rsync is a powerful tool for synchronization and backups. It only copies changes.