The `gzip` Command in Linux

The gzip utility is not only one of the most popular file compression tools in Linux, but also a powerful program with many advanced features.


Compression Optimization: Controlling the Compression Level

gzip allows you to specify the compression level from 1 to 9:

  • 1 or --fast – maximum speed with minimal compression.
  • 9 or --best – maximum compression ratio, but higher CPU usage.

To compress a file with the maximum compression level, run:

gzip -9 filename

Compressing Data from Standard Input

gzip can compress not only files, but also data from standard input.
For example, to compress the output of another command:

mysqldump database_name | gzip > backup.sql.gz

Viewing Compression Statistics Without Extracting

To see compression statistics without decompressing the file:

gzip -l filename.gz

Or with more detailed output:

gzip -lv filename.gz

Recursive File Compression and Decompression

To recursively compress all files in a directory:

gzip -r directory_name

To recursively decompress all files in a directory:

gzip -dr directory_name

Working with .tar.gz Archives

gzip is often used together with the tar command to create compressed archives.

To create a .tar.gz archive:

tar -czf archive.tar.gz directory_name

To extract a .tar.gz archive:

tar -xzf archive.tar.gz

🚀 Explore more guides on our blog 👉 blog.1it.pro
📧 Contact us: admin@1it.pro for expert IT guidance.
🌐 Explore more: Visit 1it.pro for top-tier IT solutions.

UA EN RU

Зв'язатися з нами

Telegram Email