Linux GZip Compression Tricks

From its manual: Gzip reduces the size of the named files using Lempel-Ziv coding (LZ77). Whenever possible, each file is replaced by one with the extension .gz, while keeping the same ownership modes, access and modification times.

Gzip is one of the most powerful tools in linux for compressing files/folders.

Basic compression.

gzip test.mp4

This is the very basic gzip compression command. The output will be test.mp4.gz but be advised that the original file will be deleted.

Compressing file/s without deleting the original file, -c option must be used.

gzip -c test.mp4 > test.mp4.gz

Compression in verbose mode.

gzip -v -c test.mp4 > test.mp4.gz

Compressing file at its best compressed output, -9 option is used.

gzip -v -9 -c test.mp4 > test.mp4.gz

If you have big file/s and you want to compress it faster, use -1.

gzip -v -1 -c test.mp4 > test.mp4.gz

Recursively compressing files inside a diretory using -r option. Note that this will replace the original with compressed file.

gzip -r -v -9 -c Folder/

If you only want to test how many percent of file will be compressed without having to actually write the output, pipe it to /dev/null. Source: The Ninja SysAdmin.

gzip -v -9 -c test.mp4 > /dev/null

That’s gzip for you ^_^.