Compression and Archiving Commands in Linux (original) (raw)

Last Updated : 7 Jan, 2026

Compression and archiving commands in Linux are used to reduce file sizes, combine multiple files into a single archive, and extract compressed data when needed. These commands help save disk space, speed up file transfers, and simplify backup and distribution of files.

Below are the commonly used Compression and Archiving Commands in Linux

compression_and_archiving_commands

1. ar

The ar command is used to create, modify, and extract files from archives, mainly used for static libraries.

**Syntax:

ar [options] archive_name file_name

**Example:

ar p super.a

This is used to print the specified members of a archive in a standard output file if you do not use modifier it will print member as it is an output file whereas if you use modifier v then it will show member name before it is copied to output file.

2. bzcmp

The bzcmp command compares two bzip2-compressed files.

**Syntax:

bzcmp file1.bz2 file2.bz2

**Example:

Lightbox

bzcmp compares the file1.bz2 and file2.bz2 and returns the first-byte position where the data differs

3. bzdiff

The bzdiff command compares bzip2-compressed files line by line.

**Syntax:

bzdiff file1.bz2 file2.bz2

**Example:

compressing two files

bzip2 file1
bzip2 file2

bzdiff file1.bz2 file2.bz2

4. bzgrep

The bzgrep command searches text inside bzip2-compressed files.

**Syntax:

bzgrep "pattern" file.bz2

**Example:

Take a normal text file, use grep on it. Then compress it using bzip2 and search the specific pattern in the compressed file with bzgrep.

bzgrep

5. bzip2

The bzip2 command compresses files using the bzip2 algorithm.

**Syntax:

bzip2 [OPTIONS] filenames ...

**Example:

​bzip2 -k file1.txt

bz2

6. bzless

The bzless command views bzip2-compressed files page by page.

**Syntax:

bzless [less_options] file.

**Example:

bzless file1.bz2

7. bzmore

The bzmore command displays compressed file content one screen at a time.

**Syntax:

bzmore file.bz2

**Example:

A text file named _GFG.txt is compressed via _bzip2. After the compression, the file is saved as GFG.txt.bz2. In this file, for instance contains numbers ranging from 1 to 40 like this:

1
2
3
.
.
.
40

Now, To view the contents of this file execute the following command:

bzmore GFG.txt.bz2

view content of file through bzmore

8. gunzip

The gunzip command decompresses gzip-compressed files.

**Syntax:

gunzip file.gz

**Example: Decompress a Single .gz File

gunzip example.txt.gz

file

9. gzip

The gzip command compresses files using the GNU zip algorithm.

**Syntax:

gzip file_name

**Example:

Compress a file using the gzip command in Linux

gzip mydoc.txt

Decompress a gzip File in Linux

gzip -d mydoc.txt.gz

This command decompresses the specified gzip file, leaving the original uncompressed file intact.

**Output:

file

Here,

10. gzexe

The gzexe command compresses executable files.

**Syntax:

gzexe file_name

**Example:

grexe hello.sh

file

11. zip

The zip command creates ZIP archives.

**Syntax:

zip archive_name.zip file_name

12. zdiff

The zdiff command compares gzip-compressed files.

**Syntax:

zdiff file1.gz file2.gz

**Example:

zdiff file1.gz file2.gz

**zdiff compares file1.gz and file2.gz and returns the lines in which the difference occurs.

Creating two files and compressing them.

Now comparing the two given files.

13. zgrep

The zgrep command searches inside gzip-compressed files.

**Syntax:

zgrep "pattern" file.gz

**Example:

zgrep -c "linux" GFG.txt.gz

This option is used to display the number of matching lines for each file.