<http://schema.org/articleBody>
"&amp;lt;h3&amp;gt;Introduction&amp;lt;/h3&amp;gt;&amp;lt;p&amp;gt;If you look through your folders and find files with an extension of &amp;amp;#34;.gz&amp;amp;#34; then it means they have been compressed using &amp;lt;a href=&amp;quot;https://www.lifewire.com/example-uses-of-the-linux-gzip-command-4078675&amp;quot; data-component=&amp;quot;link&amp;quot; data-source=&amp;quot;inlineLink&amp;quot; data-type=&amp;quot;internalLink&amp;quot; data-ordinal=&amp;quot;1&amp;quot;&amp;gt;the &amp;amp;#34;gzip&amp;amp;#34; command&amp;lt;/a&amp;gt;.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;The &amp;amp;#34;gzip&amp;amp;#34; command uses the Lempel-Ziv (&amp;lt;a href=&amp;quot;https://en.wikipedia.org/wiki/LZ77_and_LZ78&amp;quot; data-component=&amp;quot;link&amp;quot; data-source=&amp;quot;inlineLink&amp;quot; data-type=&amp;quot;externalLink&amp;quot; data-ordinal=&amp;quot;2&amp;quot;&amp;gt;ZZ77&amp;lt;/a&amp;gt;) compression algorithm to reduce the size of files such as documents, images and audio tracks.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;Of course after you have compressed a file using &amp;amp;#34;gzip&amp;amp;#34; you will at some stage want to decompress the file again.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;In this guide I will show you how to decompress a file which has been compressed using the &amp;amp;#34;gzip&amp;amp;#34; command.&amp;lt;/p&amp;gt;&amp;lt;h3&amp;gt;Decompress Files Using The &amp;amp;#34;gzip&amp;amp;#34; Command&amp;lt;/h3&amp;gt;&amp;lt;p&amp;gt;The &amp;amp;#34;gzip&amp;amp;#34; command itself provides a method for decompressing files with the &amp;amp;#34;.gz&amp;amp;#34; extension.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;In order to decompress a file you need to use minus d (-d) switch as follows:&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;gzip -d myfilename.gz&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;p&amp;gt;The file will be decompressed and the &amp;amp;#34;.gz&amp;amp;#34; extension will be removed.&amp;lt;/p&amp;gt;&amp;lt;h3&amp;gt;Decompress A File Using The &amp;amp;#34;gunzip&amp;amp;#34; Command&amp;lt;/h3&amp;gt;&amp;lt;p&amp;gt;Whilst using the &amp;amp;#34;gzip&amp;amp;#34; command is perfectly valid it is much easier to remember just to use &amp;amp;#34;gunzip&amp;amp;#34; to decompress a file as shown in the following example:&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;gunzip myfilename.gz&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;h3&amp;gt;Force\u00A0A File To Decompress&amp;lt;/h3&amp;gt;&amp;lt;p&amp;gt;Sometimes the &amp;amp;#34;gunzip&amp;amp;#34; command has issues with decompressing a file.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;A common reason for &amp;amp;#34;gunzip&amp;amp;#34; refusing to decompress a file is where the filename that will be left after decompression is the same as one that already exists.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;For instance imagine you have a file called &amp;amp;#34;document1.doc.gz&amp;amp;#34; and you wish to decompress it using the &amp;amp;#34;gunzip&amp;amp;#34; command. Now imagine you also have a file called &amp;amp;#34;document1.doc&amp;amp;#34; in the same folder.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;When you run the following command a message will appear stating that the file already exists and you will be asked to confirm the action.&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;gunzip document1.doc.gz&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;p&amp;gt;You can of course enter &amp;amp;#34;Y&amp;amp;#34; to accept that the existing file will be overwritten. If you are implementing &amp;amp;#34;gunzip&amp;amp;#34; as part of a script however then you won&amp;amp;#39;t want a message to be displayed to the user because it stops the script from running and requires input.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;You can force the &amp;amp;#34;gunzip&amp;amp;#34; command to decompress a file by using the following syntax:&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;gunzip -f document1.doc.gz&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;p&amp;gt;This will overwrite an existing file of the same name and it will not prompt you whilst doing so. You should make sure therefore that you use the minus f (-f) switch carefully.&amp;lt;/p&amp;gt;&amp;lt;h3&amp;gt;How To Keep Both The Compressed And Decompressed File&amp;lt;/h3&amp;gt;&amp;lt;p&amp;gt;By default the &amp;amp;#34;gunzip&amp;amp;#34; command will decompress the file and the extension will be removed. Therefore a file called &amp;amp;#34;myfile.gz&amp;amp;#34; will now be called &amp;amp;#34;myfile&amp;amp;#34; and it will be expanded to full size.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;It may be the case that you want to decompress the file but also keep a copy of the compressed file.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;You can achieve this by running the following command:&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;gunzip -k myfile.gz&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;p&amp;gt;You will now be left with &amp;amp;#34;myfile&amp;amp;#34; and &amp;amp;#34;myfile.gz&amp;amp;#34;.&amp;lt;/p&amp;gt;&amp;lt;h3&amp;gt;Displaying Compressed Output&amp;lt;/h3&amp;gt;&amp;lt;p&amp;gt;If the compressed file is a text file then you can view the text within it without having to decompress it first.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;To do this use the following command:&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;gunzip -c myfile.gz&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;p&amp;gt;The above command will display the contents of myfile.gz to the terminal output.&amp;lt;/p&amp;gt;&amp;lt;h3&amp;gt;Display Information About The Compressed File&amp;lt;/h3&amp;gt;&amp;lt;p&amp;gt;You can find out more information about a compressed file using the &amp;amp;#34;gunzip&amp;amp;#34; command as follows:&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;gunzip -l myfile.gz&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;p&amp;gt;The output of the above command shows the following values:&amp;lt;/p&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Compressed Size&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Uncompressed Size&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Ratio&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Uncompressed Filename&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&amp;lt;p&amp;gt;The most useful aspect of this command is when you are &amp;lt;a href=&amp;quot;https://www.lifewire.com/transferbigfiles-com-free-sending-service-1173973&amp;quot; data-component=&amp;quot;link&amp;quot; data-source=&amp;quot;inlineLink&amp;quot; data-type=&amp;quot;internalLink&amp;quot; data-ordinal=&amp;quot;3&amp;quot;&amp;gt;dealing with large files&amp;lt;/a&amp;gt; or a drive which is low on disk space.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;Imagine you have a drive which is 10 gigabytes in size and the compressed file is 8 gigabytes. If you blindly run the &amp;amp;#34;gunzip&amp;amp;#34; command then you might find that the command fails because the uncompressed size is 15 gigabytes.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;By running the &amp;amp;#34;gunzip&amp;amp;#34; command with the minus l (-l) switch you can v&amp;lt;a href=&amp;quot;https://www.lifewire.com/check-disk-space-commands-df-du-2201111&amp;quot; data-component=&amp;quot;link&amp;quot; data-source=&amp;quot;inlineLink&amp;quot; data-type=&amp;quot;internalLink&amp;quot; data-ordinal=&amp;quot;4&amp;quot;&amp;gt;erify that the disk that you are decompressing the file to has enough space&amp;lt;/a&amp;gt;. You can also see the file name that will be used when the file is decompressed.&amp;lt;/p&amp;gt;&amp;lt;h3&amp;gt;Decompressing Lots Of Files Recursively&amp;lt;/h3&amp;gt;&amp;lt;p&amp;gt;If you want to decompress all the files in a folder and all the files in all of the folders below that you can use the following command:&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;gunzip -r foldername&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;p&amp;gt;For example imagine you have the following folder structure and files:&amp;lt;/p&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Documents&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;mydoc.gz&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;mydoc1.gz&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Accounts&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;spreadsheet1.gz&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;spreadsheet2.gz&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&amp;lt;p&amp;gt;You can decompress all of the files by running the following command:&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;gunzip -r Documents&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;h3&amp;gt;Test Whether A Compressed File Is Valid&amp;lt;/h3&amp;gt;&amp;lt;p&amp;gt;You can test whether a file has been compressed using &amp;amp;#34;gzip&amp;amp;#34; by running the following command:&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;gunzip -t filename.gz&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;p&amp;gt;If the file is invalid you will receive a message otherwise you will be returned to the input with no message.&amp;lt;/p&amp;gt;&amp;lt;h3&amp;gt;What Exactly Happened When You Decompressed The File&amp;lt;/h3&amp;gt;&amp;lt;p&amp;gt;By default when you run the &amp;amp;#34;gunzip&amp;amp;#34; command you are just left with a decompressed file without the &amp;amp;#34;gz&amp;amp;#34; extension.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;If you more information you can use the minus v (-v) switch to show &amp;lt;a href=&amp;quot;https://www.lifewire.com/definition-of-verbose-output-2198791&amp;quot; data-component=&amp;quot;link&amp;quot; data-source=&amp;quot;inlineLink&amp;quot; data-type=&amp;quot;internalLink&amp;quot; data-ordinal=&amp;quot;5&amp;quot;&amp;gt;verbose information&amp;lt;/a&amp;gt;:&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;gunzip -v filename.gz&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;p&amp;gt;The output will be something like this:&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;filename.gz: 20% -- replaced with filename&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;p&amp;gt;This tells you the original compress filename, how much it was decompressed and the final filename.&amp;lt;/p&amp;gt;"^^<http://www.w3.org/2001/XMLSchema#string>
<https://www.lifewire.com/example-uses-of-the-gunzip-command-4081346>