gunzip Command Examples in Linux

The gzip program is used to compress one or more files. When executed, it replaces the original file with a compressed version of the original. The corresponding gunzip program is used to restore compressed files to their original, uncompressed form. Here is an example:

$ ls -l /etc > foo.txt
$ ls -l foo.*
-rw-r--r-- 1 me    me     15738 2012-10-14 07:15 foo.txt
$ gzip foo.txt
$ ls -l foo.*
-rw-r--r-- 1 me    me    3230 2012-10-14 07:15 foo.txt.gz
$ gunzip foo.txt
$ ls -l foo.*
-rw-r--r-- 1 me    me     15738 2012-10-14 07:15 foo.txt

In this example, we create a text file named foo.txt from a directory listing. Next, we run gzip, which replaces the original file with a compressed version named foo.txt.gz. In the directory listing of foo.*, we see that the original file has been replaced with the compressed version and that the compressed version is about one-fifth the size of the original. We can also see that the compressed file has the same permissions and time stamp as the original.

Next, we run the gunzip program to uncompress the file. Afterward, we can see that the compressed version of the file has been replaced with the original, again with the permissions and timestamp preserved.

gunzip Command Examples

1. To unzip any compressed file:

# gunzip file.gz

2. To get the License information:

# gunzip -L
# gunzip --license

3. To test the zipped files integrity:

# gunzip -t file.gz
# gunzip --test file.gz

4. To list the compressed files information:

# gunzip -l file.gz
# gunzip --list file.gz

5. To save the original name or server time stamp:

# gunzip -N file.gz
# gunzip --name file.gz

6. To operate in verbose mode:

# gunzip -v file.gz
# gunzip --verbose file.gz

7. To get the version info:

# gunzip -V
# gunzip --version

8. To get the better decompression:

# gunzip -9 file.gz
# gunzip --best file.gz

9. To get the faster decompression:

# gunzip -1 file.gz
# gunzip --faster file.gz

10. To read zipped file contents:

# gunzip -c file.gz
Related Post