Linux Tutorial

Linux File/Directory Management

Linux Packaging And Compression

Vim Text Editor

Linux Text Processing

Linux Software Installation

Linux User/User Group Management

Linux Permission Management

Linux Filesystem Management

Linux Advanced Filesystem Management

Linux System Management

Linux Backup and Recovery

Linux System Service Management

Linux System Log Management

Linux Boot Management

LAMP/LNMP Environment

SELinux Management

Linux gunzip Command: Unzip A ".gz" File

The gunzip command in Linux is used to decompress files that have been compressed using the gzip utility. The gzip utility compresses files using the Lempel-Ziv (LZ77) algorithm, and the compressed files usually have a .gz extension. The gunzip command restores the original file by decompressing the compressed file. In this tutorial, we'll go over some basic usage examples for the gunzip command.

  • Decompress a single file:

To decompress a single file using gunzip, simply provide the file as an argument:

gunzip file.gz

This will decompress file.gz and create the original file file in the same directory. The compressed file file.gz will be removed.

  • Decompress multiple files:

You can decompress multiple .gz files in a single command by providing multiple file names as arguments:

gunzip file1.gz file2.gz file3.gz
  • Decompress files without deleting the compressed files:

By default, gunzip will remove the compressed file after decompressing it. If you want to keep the compressed file, use the -k or --keep option:

gunzip -k file.gz
  • Decompress files to a specific directory:

If you want to decompress a file and store the decompressed file in a different directory, you can use the -c option in combination with file redirection:

gunzip -c file.gz > /path/to/directory/file

This will decompress file.gz and create the decompressed file in the specified directory without modifying the original compressed file.

  • Decompress files with custom extensions:

gunzip can also decompress files that don't have the standard .gz extension. To do this, use the -S or --suffix option:

gunzip -S .custom file.custom

This command will decompress file.custom and create the decompressed file file.

In summary, the gunzip command in Linux is a useful tool for decompressing files that have been compressed with the gzip utility. By understanding its various options and arguments, you can efficiently decompress files, work with custom file extensions, and manage the output of decompressed files.

  1. How to use the gunzip command in Linux:

    gunzip is a command-line utility in Linux used to decompress gzip files. It's often used in conjunction with the gzip compression tool.

    Example code:

    gunzip filename.gz
    
  2. Unzipping .gz files with gunzip:

    Unzipping a .gz file is straightforward with the gunzip command.

    Example code:

    gunzip file.gz
    
  3. Decompressing gzip files using gunzip:

    gunzip can be used to decompress gzip files, which have the .gz extension.

    Example code:

    gunzip data.gz
    
  4. Handling compressed archives with gunzip in Linux:

    gunzip can handle compressed archives containing multiple gzip files. It's commonly used in combination with tar for extracting compressed tarballs.

    Example code:

    tar -xzf archive.tar.gz
    
  5. Recursive unzipping with gunzip:

    To recursively unzip all .gz files in a directory and its subdirectories, you can use the find command.

    Example code:

    find /path/to/directory -type f -name "*.gz" -exec gunzip {} \;
    
  6. Preserving original files during gunzip:

    By default, gunzip removes the original gzip file after decompressing. To preserve the original file, you can use the -k option.

    Example code:

    gunzip -k data.gz
    
  7. Viewing progress and status in gunzip command:

    The gunzip command doesn't provide a built-in progress indicator. However, you can use tools like pv (Pipe Viewer) in combination with gunzip to view progress.

    Example code:

    pv file.gz | gunzip > output_file
    
  8. Extracting specific files from a gzip archive with gunzip:

    If you have a gzip archive containing multiple files and you want to extract only specific files, you can use the -c option to extract to standard output and then redirect the output.

    Example code:

    gunzip -c archive.gz file.txt > extracted_file.txt