Back to course

77. Compression Tools: `gzip` and `bzip2`

Linux Basics: From Zero to CLI Hero

Reducing File Size

Compression tools reduce the size of individual files. They typically replace the original file with the compressed version.

1. gzip

Creates files with the .gz extension. Generally faster compression but slightly less efficient than bzip2.

bash $ gzip large_log.txt

Original file is replaced by large_log.txt.gz

Decompress using gunzip or gzip -d

$ gunzip large_log.txt.gz

Restores large_log.txt

2. bzip2

Creates files with the .bz2 extension. Slower compression but often achieves smaller file sizes.

bash $ bzip2 archive.tar

Replaced by archive.tar.bz2

Decompress using bunzip2 or bzip2 -d

$ bunzip2 archive.tar.bz2

3. Viewing Compressed Files (zcat and bzcat)

These commands allow you to view the contents of a compressed file without decompressing it first.

bash $ zcat large_log.txt.gz | less