Top 12 Examples of Gzip and Gunzip Commands in Linux

Gzip and Gunzip Command Linux

Gzip is a widely used command-line tool for compressing files, while gunzip is its counterpart for decompressing .gz files. Both tools utilize the Lempel-Ziv (LZ77) compression algorithm, providing a balance between compression speed and efficiency in reducing file sizes.

Here are various ways to use the gzip and gunzip command:

  1. Compressing a Single File
  2. Compressing Multiple Files
  3. Keeping the Original File While Compressing
  4. Applying Maximum Compression
  5. Using the Fastest Compression Method
  6. Testing a Compressed File for Integrity
  7. Forcing Overwrite of an Existing .gz File
  8. Decompressing a .gz File
  9. Keeping the Compressed File While Decompressing
  10. Decompressing Multiple .gz Files
  11. Verifying the Integrity of a .gz File
  12. Decompressing with Verbose Output

1. Compressing a Single File:

gzip file.txt

This replaces file.txt with file.txt.gz.

2. Compressing Multiple Files:

gzip file1.txt file2.txt file3.txt

Each file will be compressed individually.

3. Keeping the Original File While Compressing:

gzip -k file.txt

The -k option ensures that the original file.txt remains after compression.

4. Applying Maximum Compression:

gzip -9 largefile.log

The -9 flag instructs gzip to use the highest level of compression.

5. Using the Fastest Compression Method:

gzip -1 quickfile.txt

The -1 option prioritizes speed over compression efficiency.

6. Testing a Compressed File for Integrity:

gzip -t file.txt.gz

This checks whether the .gz file is valid or corrupted.

7. Forcing Overwrite of an Existing .gz File:

gzip -f file.txt

This replaces an existing .gz file without confirmation.

8. Decompressing a .gz File:

gunzip file.txt.gz

This restores file.txt.gz to file.txt and removes the compressed version.

9. Keeping the Compressed File While Decompressing:

gunzip -k file.txt.gz

The -k flag ensures that file.txt.gz remains intact after extraction.

10. Decompressing Multiple .gz Files:

gunzip file1.txt.gz file2.txt.gz

This extracts both files while deleting their .gz versions.

11. Verifying the Integrity of a .gz File:

gunzip -t file.txt.gz

This command checks if the compressed file is valid and free from corruption.

12. Decompressing with Verbose Output:

gunzip -v file.txt.gz

The -v option provides detailed output about the decompression process.

These resources provide further insights into the available options and best practices for using gzip and gunzip efficiently.

Related Posts

Leave a Reply