gunzip Command

Purpose

Decompresses files that are compressed with gzip, zip, or compress command.

Syntax

gunzip [ -c ] [ -d ] [ -f ] [ -k ] [ -l ] [ -N ] [ -n ] [ -q ] [ -r ] [ -S ] [ -t ] [ -v ] [ -V ] [ -h ] [ filename ]...

Description

The gunzip command decompresses files that are compressed with gzip, zip, or compress command. The gunzip command replaces each compressed file with its decompressed version and removes the original .gz, .z, or -z extension unless the -k option is used. This command can also list contents of compressed files or write decompressed output to the standard output. If the input data is not in a supported compressed format, it is copied to the output unchanged. When no file is specified or when a file name of - is specified, the gunzip command reads from the standard input and writes decompressed data to the standard output.

Flags

Table 1. Flags
Item Description
-c, --stdout, or --to-stdout Writes output to the standard output and keeps the original files unchanged.
-d or --decompress Decompresses the files. Thins option is the default option for gunzip command.
-f or --force Forces decompression even if the output file exists or if the input is not compressed.
-k or --keep Retains input files during decompression.
-l or --listList Displays information about the compressed file such as compressed capacity, decompressed capacity, ratio, name.
-N or --name Restores the original file name and timestamp, if present, during the decompression.
-n or --no-name Does not save or restore the original file name and timestamp.
-q or --quiet Suppresses all the warning messages.
-r or --recursive Recursively decompresses files in directories.
-S .suf or --suffix .suf Uses the suffix .suf instead of .gz when it searches for compressed files.
-t or --test Tests the integrity of the compressed file.
-v or --verbose Displays information in verbose mode. Thins option display name and percentage reduction for each file that is processed.
-V or --version Displays version information.
-h or --help Displays help about the gunzip command.

Exit status

This command returns the following exit values:

Table 2. Exit status
Item Description
0 Successful completion.
1 An error occurred.
2 A warning is issued.

Examples

  1. To decompress the file.gz file, enter the following command:
    gunzip file.gz
  2. To decompress all .gz files verbosely, enter the following command:
    gunzip -v *.gz
  3. To decompress the data.gz file without deleting the original file, enter the following command:
    gunzip -k data.gz 
  4. To list the contents of the archive.gz file, enter the following command:
    gunzip -l archive.gz 
  5. To decompress the file.gz file and direct the output to the standard output, enter the following command:
    gunzip -c file.gz > file
  6. To recursively decompress all .gz files in the /backup folder, enter the following command:
    gunzip -r /backup