Fundamentals 5 min read

Common Linux Compression and Decompression Commands

This article provides a concise reference of frequently used Linux commands for compressing and extracting files in various formats such as tar, gz, bz2, zip, rar, and more, including syntax, options, and practical notes for each archive type.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
Common Linux Compression and Decompression Commands

Common Linux compression and decompression commands are listed below.

.tar

Extract: tar xvf FileName.tar
Create archive: tar cvf FileName.tar DirName
(Note: tar creates an archive but does not compress.)

.gz

Extract 1: gunzip FileName.gz
Extract 2: gzip -d FileName.gz
Compress: gzip FileName

.tar.gz and .tgz

Extract: tar zxvf FileName.tar.gz
Compress: tar zcvf FileName.tar.gz DirName

.bz2

Extract 1: bzip2 -d FileName.bz2
Extract 2: bunzip2 FileName.bz2
Compress: bzip2 -z FileName

.tar.bz2

Extract: tar jxvf FileName.tar.bz2
Compress: tar jcvf FileName.tar.bz2 DirName

.bz

Extract 1: bzip2 -d FileName.bz
Extract 2: bunzip2 FileName.bz

.tar.bz

Extract: tar jxvf FileName.tar.bz

.Z

Extract: uncompress FileName.Z
Compress: compress FileName

.tar.Z

Extract: tar Zxvf FileName.tar.Z
Compress: tar Zcvf FileName.tar.Z DirName

.zip

Extract: unzip FileName.zip
Compress: zip FileName.zip DirName

.rar

Extract: rar x FileName.rar
Compress: rar a FileName.rar DirName

.lha

Extract: lha -e FileName.lha
Compress: lha -a FileName.lha FileName

.rpm

Extract: rpm2cpio FileName.rpm | cpio -div

.deb

Extract: ar p FileName.deb data.tar.gz | tar zxf -

Various other formats (e.g., .cpio, .slp, .arj, .ace, .lzh, .lzx, .arc, .sda, .sfx, .lnx, .zoo, .cab, .kar, .cpt, .pit, .sit, .sea)

Extract: sEx x FileName.*
Compress: sEx a FileName.* FileName

gzip command

Reducing file size saves storage space and shortens network transfer time; gzip is a commonly used Linux command for compressing and decompressing files.

Syntax: gzip [options] file

-a or --ascii: use ASCII mode
-d or --decompress or --uncompress: decompress files
-f or --force: force compression, ignore existing files or links
-h or --help: display help
-l or --list: list archive contents
-L or --license: show license information
-n or --no-name: do not store original name and timestamp
-N or --name: store original name and timestamp
-q or --quiet: suppress warnings
-r or --recursive: process directories recursively
-S
or --suffix
: change suffix string
-t or --test: test archive integrity
-v or --verbose: show detailed operation
-V or --version: display version
-1 to -9: set compression level (1 fastest, 9 best; default 6)
--best: same as -9
--fast: same as -1
-c or --stdout or --to-stdout: output to standard output
Linuxshellcommand linecompressionfile archiving
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.