gunzip command is used to compress or expand a file or a list of files in Linux. It accepts all the files having extension as .gz, .z, _z, -gz, -z , .Z, .taz or.tgz and replace the compressed file with the original file by default. The files after uncompression retain its actual extension.
gunzip [Option] [archive name/file name]
Example 1: The argument that is passed here is: geeksforgeeks.txt which is a compressed text file.
Example 2: The argument that is passed here is: geeksforgeeks.txt.gz which is a compressed file.
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 in Example 2 as 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:
gunzip [file1] [file2] [file3]...
- -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.
gunzip -c geeksforgeeks.txt.tar.gz
- -f: To decompress a file forcefully.
gunzip -f geeksforgeeks.txt.tar.gz
Output: The file will be forcefully extracted.
- -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.
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.
gunzip -l geeksforgeeks.txt.tar.gz
- -L: This option displays the software license and exit.
- -r: This option is used to uncompress all the files within the folder and subfolder recursively.
gunzip -r [Directory/Folder path]
This will extract all the compressed files recursively within the path /home/sc.
- -t: To test whether the file is valid or not.
gunzip -t [File name]
- -v: This option is used to get verbose information such as the file name, decompression percentage, etc.
gunzip -v geeksforgeeks.txt.gz
- -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.
- -d: This option simply decompresses a file.
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.
- cp command in Linux with examples
- more command in Linux with Examples
- which command in Linux with examples
- rev command in Linux with Examples
- apt-get command in Linux with Examples
- cmp Command in Linux with examples
- cut command in Linux with examples
- tee command in Linux with examples
- ln command in Linux with Examples
- ex command in Linux with examples
- at Command in Linux with Examples
- ar command in Linux with examples
- id command in Linux with examples
- df Command in Linux with examples
- yes command in Linux with Examples
- man command in Linux with Examples
- ip command in Linux with examples
- tty command in Linux with examples
- dc command in Linux with examples
- for command in Linux with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : shubham_singh