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 reboot Command: Restart the System Safely

Linux reboot Command: Restart the System Safely

Learn how to restart the System Safely with the Linux reboot command, including practical examples, key options, and important precautions.

Linux nc Command: Test TCP and UDP Connections

Linux nc Command: Test TCP and UDP Connections

Learn how to test TCP and UDP Connections with the Linux nc command, including practical examples, key options, and important precautions.

Linux rm Command: Remove Files and Directories Safely

Linux rm Command: Remove Files and Directories Safely

Learn how to remove files and directory trees with Linux rm, use interactive safeguards, limit recursive deletion, and avoid destructive path mistakes.

Linux command Command: Run Commands While Bypassing Aliases and Functions

Linux command Command: Run Commands While Bypassing Aliases and Functions

Learn how to use the Linux command command to check command availability and bypass shell aliases or functions, with essential options, practical examples, output interpretation, and common troubleshooting tips.

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.

Linux lsmod Command: List Loaded Kernel Modules

Linux lsmod Command: List Loaded Kernel Modules

Learn how to list Loaded Kernel Modules with the Linux lsmod command, including practical examples, key options, and important precautions.

Linux dnf Command: Manage RPM Distribution Packages

Linux dnf Command: Manage RPM Distribution Packages

Learn how to manage RPM Distribution Packages with the Linux dnf command, including practical examples, key options, and important precautions.

Linux sync Command: Flush Buffered Writes to Storage

Linux sync Command: Flush Buffered Writes to Storage

Learn how to flush Buffered Writes to Storage with the Linux sync command, including practical examples, key options, and important precautions.

Linux curl Command: Make URL Requests and Inspect HTTP Responses

Linux curl Command: Make URL Requests and Inspect HTTP Responses

Learn how to make URL Requests and Inspect HTTP Responses with the Linux curl command, including practical examples, key options, and important precautions.

Linux printenv Command: Print Environment Variable Values

Linux printenv Command: Print Environment Variable Values

Learn how to use the Linux printenv command to print all environment variables or selected variable values, with essential options, practical examples, output interpretation, and common troubleshooting tips.