gunzip Command in Linux with Examples (original) (raw)

Last Updated : 13 May, 2026

The gunzip command in Linux is used to decompress files that were compressed using the gzip command, restoring them to their original form.

Example: Decompress a Single .gz File

Extracts example.txt.gz and restores it as example.txt, deleting the .gz file after decompression.

**Command:

gunzip example.txt.gz

**Output:

file

Output

Syntax

gunzip [options] archivename.gz

Commonly Used gunzip Command Options

1. '-c': Write output to standard output (stdout)

Displays decompressed content directly on the terminal instead of saving it. Useful for viewing file content without extracting to disk.

**Command:

gunzip -c geeksforgeeks.txt.tar.gz

**Output:

2. '-k': Keep original compressed file

Decompresses the .gz file but retains the original file.txt.gz. Handy when you want both compressed and uncompressed versions.

**Command:

gunzip -k example1.txt.gz

**Output:

file

Output

3. '-f': Force decompression

Automatically overwrites existing files without prompting for confirmation. Useful in scripts or batch operations where manual confirmation isn’t possible.

**Command:

gunzip -f example1.txt.gz

**Output:

file

Output

4. '-r': Recursive decompression

Decompresses all .gz files within the specified directory and its subdirectories. Saves time when handling multiple compressed files in nested folders.

**Command:

gunzip -r /home/vboxuser/gfg/

**Output:

file

Output

5. '-v': Verbose mode

Displays detailed information while decompressing each file. Helps monitor the progress and confirms which files are being processed.

**Command:

gunzip -v file1.txt.gz

**Output:

file

Output

6. '-t': Test integrity of file

Verifies whether a .gz file is valid and not corrupted. Does not decompress the file; only checks its consistency.

**Command:

gunzip -t example2.txt.gz

**Output:

file

Output

7. '-l': List compression details

Displays compression statistics like original size, ratio, and name. Useful for checking space savings and compression efficiency.

**Command:

gunzip -l example2.txt.gz

**Output:

file

8. '-h': Display Help

Shows help information and exits. Lists available options for the gunzip command.

**Command:

gunzip -help

**Output:

Some Other Options: