gunzip

gunzip

The gunzip command in Unix and Linux is used to decompress files that have been compressed with gzip. It is a straightforward tool for handling gzip-compressed files and is commonly used for file decompression tasks.

Basic Usage

The basic syntax for the gunzip command is:

gunzip [options] [file(s)]
  • options: Optional command-line options to control the behavior of gunzip.

  • file(s): The name(s) of the file(s) to decompress.

Examples

Decompressing a File

To decompress a file using gunzip:

gunzip filename.txt.gz

This command decompresses filename.txt.gz and restores it to filename.txt.

Decompressing with -d Option

The -d option can also be used to achieve the same result:

gunzip -d filename.txt.gz

Decompressing Multiple Files

To decompress multiple files at once:

This command decompresses file1.txt.gz and file2.txt.gz, resulting in file1.txt and file2.txt.

Options

Keep Original File

  • -k: Keep the original compressed file after decompression.

Verbose Output

  • -v: Verbose mode, display decompression statistics.

Practical Use Cases

Automated Decompression

To decompress all .gz files in a directory and its subdirectories:

This command recursively decompresses all .gz files under /path/to/files.

Keeping Original Files

To keep the original .gz files after decompression:

This command decompresses file1.txt.gz and file2.txt.gz while keeping the original compressed files.

Summary

The gunzip command is a simple yet effective tool for decompressing gzip-compressed files in Unix and Linux environments. It offers options for maintaining original files, providing verbose output, and handling multiple files simultaneously. Understanding its usage and options can help you efficiently manage file decompression tasks on your system.

help

Last updated