Linux Commands | Archive File Management | gz Compress and Extract

Compress with gz

Command

gzip {file name to compress}

Compress a File

To compress aaa.jpg with gz, use the following command.

gzip aaa.jpg

As a result, aaa.jpg is removed and the compressed file aaa.gz is created.

gz is not intended for compressing multiple files into one archive. To compress multiple files, use tar, zip, or 7z.

Extract gz

Command

gzip -d {archive file name}.gz

To extract a file compressed with gzip, use the -d option. -d is short for “decompress”.

Install gzip

gzip is installed by default on Linux. If the gzip command cannot be found, install it with the command below.

Install gzip on Ubuntu

apt-get install gzip