Skip to content

Linux gunzip command

The Linux gunzip command is used to decompress gzip files in the terminal. It is a simple and efficient tool for unpacking files that have been compressed using gzip compression. By running the gunzip command followed by the name of the gzip file you want to decompress, you can quickly extract the original uncompressed file. Gunzip is often used in combination with other Linux commands to streamline file compression and decompression processes.

gunzip Syntax:

Terminal window
gunzip [option] [parameter]

Options:

OptionDescription
-cWrite output on standard output; keep original files unchanged.
-dDecompress.
-fForce. Ignore nonexistent files and do not prompt.
-kKeep input files during decompression.
-lList the uncompressed size and compression ratio of the compressed files.
-rRecursively uncompress.
-tTest the integrity of the compressed files.
-vVerbose. Display the name and percentage reduction for each file processed.

Parameters:

ParameterDescription
fileThe file(s) to be decompressed.
directoryThe directory containing files to be decompressed.

gunzip Usage:

Extract a gzip-compressed file

Terminal window
gunzip file.txt.gz

This command will decompress the file.txt.gz and create a new file named file.txt.

Decompress multiple gzip-compressed files

Terminal window
gunzip *.gz

All the files with .gz extension in the current directory will be decompressed.

Keep the original gzip file

Terminal window
gunzip -k file.txt.gz

The -k option will keep the original .gz file after decompressing file.txt.gz.

Verbose output during decompression

Terminal window
gunzip -v file.txt.gz

The -v option provides verbose output, showing the progress and details of the decompression process.

How do I use gunzip in Linux?

To use the gunzip command in Linux, execute the following command:

Terminal window
gunzip file.txt.gz

What is the purpose of the gunzip command?

The gunzip command is used in Linux to decompress files that have been compressed using the gzip compression tool.

How can I list the contents of a gzip file without decompressing it?

To list the contents of a gzip file without decompressing it, you can use the zcat command along with the file name. For example:

Terminal window
zcat file.txt.gz

Can I specify a different output file name when using gunzip?

Yes, you can specify a different output file name when using gunzip by using the -c option followed by the desired output file name. For example:

Terminal window
gunzip -c file.txt.gz > output.txt

How can I decompress multiple gzip files at once using gunzip?

To decompress multiple gzip files at once using gunzip, you can use a wildcard (*) to specify the files you want to decompress. For example:

Terminal window
gunzip *.gz

Is it possible to maintain the original gzip files after decompressing with gunzip?

Yes, you can maintain the original gzip files after decompressing them with gunzip by using the -k or —keep option. For example:

Terminal window
gunzip -k file.txt.gz

How can I force the decompression of a file using gunzip?

To force the decompression of a file using gunzip, you can use the -f or —force option. For example:

Terminal window
gunzip -f file.txt.gz

Applications of the gunzip command

  • Decompresses .gz files
  • Used to extract compressed files
  • Often used in combination with tar for working with .tar.gz files