Open In App

gunzip Command in Linux with Examples

Last Updated : 11 Mar, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report
News Follow

The gunzip command in Linux is a popular tool for decompressing files compressed with gzip. It simplifies file unzipping, enhances file management, and optimizes disk space in Linux environments.

In this blog post, we will explore how gunzip works, providing practical examples for you to try. Whether you’re a Linux novice or an experienced user, you’ll learn to quickly unzip files, discover various command options, and see real-world scenarios where gunzip can save you time.

What is the gunzip Command in Linux

The gunzip command is used to decompress files that are already compressed in the zip format. Being a part of the GNU project, it compresses the data and appends the .gz extension to the file. Let’s check out the syntax below:

Syntax

Below is the syntax for gunzip command:

gunzip [Option] [archive name/file name]

Example 1:

The argument that is passed here is:

geeksforgeeks.txt which is a compressed text file.

Input:

Output:

geeksforgeeks.txt.gz

Example 2:

The argument that is passed here is:

geeksforgeeks.txt.gz which is a compressed file.

Input:

Output:

geeksforgeeks.txt

If a file is compressed using gzip command, a suffix i.e. .gz will be added to the file name after compression. Hence while uncompressing this file we can either use the original file name as shown in Example 1 or the filename with the suffix .gz as shown inExample 2as an argument.

Example 3:

In order to uncompress multiple files using the gunzip command, we can pass multiple file names as an argument as shown in the below example:

Syntax:

gunzip [file1] [file2] [file3]...

Input:

Output:

geeksforgeeks.txt, gfg.txt

Options:

  • -c: This option is used to view the text within a compressed file without uncompressing it. The ASCII/EBCDIC conversion is automatically done if it is suitable. The compressed file has to be a text file only.

Example: 4

gunzip -c geeksforgeeks.txt.tar.gz

Input

Output:

-f: To decompress a file forcefully.

Example: 5

gunzip -f geeksforgeeks.txt.tar.gz

Input

Output: The file will be forcefully extracted.

geeksforgeeks.txt

-k: This option can be used when we want to keep both the file i.e. the uncompressed and the original file after the uncompression.

Example: 6

gunzip -k geeksforgeeks.txt.tar.gz

Output: An extracted file will be added to the directory.

-l: This option is used to get the information of a compressed or an uncompressed file.

Example: 7

gunzip -l geeksforgeeks.txt.tar.gz

Input

Output:

-L: This option displays the software license and exit.

Example: 8

Input

Output:

-r: This option is used to uncompress all the files within the folder and subfolder recursively.

Syntax:

gunzip -r [Directory/Folder path]

Example: 9

This will extract all the compressed files recursively within the path /home/sc.

-t: To test whether the file is valid or not.

Syntax:

gunzip -t [File name]

-v: This option is used to get verbose information such as the file name, decompression percentage, etc.

Example: 10

gunzip -v geeksforgeeks.txt.gz

Output:

-V: This option is used to display version number.

-a: This option uses ASCII text mode to convert End-of-line characters using local conversion. This option is only supported on MS-DOS systems. When -a option is used on a Unix system, it decompresses the file ignoring the –ascii option.

Example: 11

-d: This option simply decompresses a file.

Example: 12

Output: The compressed file gets replaced by the original file i.e. geeksforgeeks.txt.

-h: This option displays the help information available and quits.

-n: This option does not save or restore the original name and time stamp while decompressing a file.

-N: This option saves or restore the original name and time stamp while decompression.

-q: This option suppresses all the warnings that arise during the execution of the command.

-s: This option use suffix SUF on compressed files.

-#: This option is used to control the speed and the amount of compression, where # can be any number between -1 to -9. -1 ensures the faster compression by decreasing the amount of compression while -9 ensures the best compression but takes more time comparatively.

Conclusion

The gunzip command in Linux is an essential tool for decompressing gzip files and restoring them to their original form. Whether you are managing file backups, managing compressed archives, or working with log files, the gunzip command is a crucial part used inLinux environment. By understanding the various options and use cases for gunzip,you can easily manage compressed files, save disk space, and improve your Linux system efficiency.



Next Article

Similar Reads

three90RightbarBannerImg