[Linux/macOS] Batch Compress Files to .gz with gzip Command

Tadashi Shigeoka ·  Tue, October 29, 2019

I’ll introduce how to batch compress files to .gz format using the gzip command on Linux and macOS.

Linux

Prerequisites: Sudden Disk Full

A sudden surge of logs caused *.log files to bloat and resulted in disk full.

I needed to free up disk space immediately, so I used the gzip command to batch compress *.log files.

Batch File Compression with gzip Command

Batch Compression with gzip *

Run the gzip * command in the directory containing log files to complete the batch compression task.

gzip *

gzip: hoge.gz already has .gz suffix -- unchanged

Even if .gz files already exist, you’ll just see an “unchanged” message like:

gzip: example.log-2019-10-29.gz already has .gz suffix -- unchanged

So it’s fine. Don’t worry about anything and just run gzip * in the directory containing log files.

That’s all from the Gemba.

Reference Information