Decompress a gzip file using the GUNZIP command in Linux

Home > Search > Linux commands
  by

The gunzip command can be used to uuncompress a gzip compressed file. Let's take an example where the /home/john.doe directory contains a gzip compressed file.

[john.doe@server1 ~]# ls -l /home/john.doe
-rw-r--r-- john.doe john.doe 12345 Jan 01 :17:16 example.file.gz

 

The gunzip command can be used to decompress example.file.gz.

[john.doe@server1 ~]# gunzip /home/john.doe/example.file.gz

 


Decompress numerous files in a directory

The -r or --recursive option can be used to uncompress every gzip compressed file at or below a directory. In this example, every file at and below /home/john.doe will be decompressed.

[john.doe@server1 ~]# gunzip -r /home/john.doe

 

 


Display the contents of the compressed file

The -c, --stdout, or --to-stdout options can be used to view the contents of a gzip compressed file. In this example, the contents of example.file.gz are displayed.

[john.doe@server1 ~]# gunzip -c /home/john.doe/example.file.gz
Hello World

 


Keep the compressed file

By default, gunzip will remove the gzip compressed file, creating a new decompressed file. The -k or --keep option can be used to save the original file, and also create a new uncompressed file.

[john.doe@server1 ~]# gunzip -k /home/john.doe/example.file.gz

 


Statistics

The -l or --list option can be used to view statistics of a compressed gzip file. The -l option will display the size of the uncompressed file, the size of the compressed file, the compression percentage, and the name of the uncompressed file.

[john.doe@server1 ~]# gunzip -l /home/john.doe/example.file.gz
compressed  uncompressed  ratio  uncompressed_name
        52           672  96.9%       example.file

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments