Linux gunzip Command: Decompress gzip Files

gunzip decompresses .gz files compressed with gzip. Since it usually converts the compressed file back to the original file, you need to specify an option if you want to keep the .gz file.

What is the gunzip command?

gunzip is the decompression function of GNU gzip and is used for the same purpose as gzip -d. When you decompress only the gzip layer in tar.gz, a .tar archive remains. To extract all directories and members, you need to use the extraction function of tar.

Basic syntax

gunzip [options] file.gz [file.gz...]

The installed implementation and options may vary depending on the distribution. Check the description on your current system with man gunzip.

Examples

Decompressing a file

Restores report.log.gz to report.log. By default, the original compressed file is removed.

gunzip report.log.gz

Preserving the compressed file

Add -k when you need to check again or use it elsewhere.

gunzip -k report.log.gz

Extract to a separate file

Restore to standard output and save to a new file. Make sure not to overwrite an existing file with the same name.

gunzip -c report.log.gz > restored-report.log

How to Check After Decompression

gunzip decompresses files compressed with .gz and by default removes the compressed file. Prepare sample files in a separate working directory and then check them.

gunzip note.txt.gz
ls -l note.txt

If successful, gunzip usually produces no output, and ls will show the restored note.txt. If a file with the same name already exists, it may ask whether to overwrite or fail.

gunzip -c note.txt.gz > newfile is useful for keeping the compressed file and writing the contents to another file. Do not assume that multiple files are combined in a single .gz. For .tar.gz, first understand the archive structure and check the list with tar -tzf.

Main Options and Format

Options/Format Description
-k Keep the input compressed file.
-c Send the restored data to standard output.
-t Check for errors without creating a file by decompressing.
-l Display the size and ratio of the compressed file, etc.
-f Can force processing without confirmation, so be careful not to overwrite.

Precautions when using

If a restoration target with the same name already exists, choose overwrite carefully. Shell redirection with -c > file can empty the existing file first. Individual files in gunzip cannot be extracted with .tar.gz alone, so use tar -xzf.

Frequently Asked Questions

If you run gunzip backup.tar.gz, will all the files be extracted?

No. Only the gzip compression is removed, usually leaving backup.tar. The files inside need to be extracted using tar.

Official Documentation

The exact behavior of options and differences depending on the implementation can be checked in the official gunzip documentation.

More in This Category
Linux resolvectl Command: Inspect systemd DNS Resolution

Linux resolvectl Command: Inspect systemd DNS Resolution

Learn how to inspect systemd DNS Resolution with the Linux resolvectl command, including practical examples, key options, and important precautions.

Linux Tutorial / File Types and Metadata: ls, file, stat, and readlink

Linux Tutorial / File Types and Metadata: ls, file, stat, and readlink

Learn what ls, file, stat, and readlink each reveal about a Linux file, including type, size, timestamps, and symbolic-link targets.

Linux ls Command: List Files and Directories

Linux ls Command: List Files and Directories

Learn how to use the Linux ls command to list files and directories with permissions, sizes, timestamps, and sorting options, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux split Command: Divide Large Files into Smaller Parts

Linux split Command: Divide Large Files into Smaller Parts

Learn how to divide Large Files into Smaller Parts with the Linux split command, including practical examples, key options, and important precautions.

Linux whoami Command: Show the Effective User Name

Linux whoami Command: Show the Effective User Name

Learn how to show the Effective User Name with the Linux whoami command, including practical examples, key options, and important precautions.

Linux renice Command: Change the Priority of a Running Process

Linux renice Command: Change the Priority of a Running Process

Learn how to change the Priority of a Running Process with the Linux renice command, including practical examples, key options, and important precautions.

Linux unzip Command: List and Extract ZIP Archives

Linux unzip Command: List and Extract ZIP Archives

Learn how to list and Extract ZIP Archives with the Linux unzip command, including practical examples, key options, and important precautions.

Linux last Command: Review Login and Reboot History

Linux last Command: Review Login and Reboot History

Learn how to use the Linux last command to review user login sessions, system reboots, and shutdown history, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux cp Command: Copy Files and Directories

Linux cp Command: Copy Files and Directories

Learn how to copy files and directories with Linux cp, control overwrites, preserve attributes, handle symlinks, and verify important copies.

Linux printf Command: Print Values with a Defined Format

Linux printf Command: Print Values with a Defined Format

Learn how to print Values with a Defined Format with the Linux printf command, including practical examples, key options, and important precautions.