{"id":16940,"date":"2023-11-01T09:54:30","date_gmt":"2023-11-01T09:54:30","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=16940"},"modified":"2023-11-01T10:20:48","modified_gmt":"2023-11-01T10:20:48","slug":"how-to-uncompress-a-gz-file-in-linux-with-gunzip-command","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2023\/11\/01\/how-to-uncompress-a-gz-file-in-linux-with-gunzip-command\/","title":{"rendered":"How to Uncompress a \u2018.gz\u2019 File in Linux With Gunzip Command."},"content":{"rendered":"\n<p>File compression is a common practice in Linux, where its users shrink files and directories using tools like&nbsp;<a href=\"https:\/\/www.ubuntumint.com\/gzip-large-files-in-linux\/\" target=\"_blank\" rel=\"noreferrer noopener\">Gzip<\/a>&nbsp;to free up storage space and increase their system\u2019s performance.<\/p>\n\n\n\n<p>This compression technique also smooths out the process of sending files across networks \u2013 fast and efficient. But here\u2019s the twist: when you need to use or change these compressed files, you wish they could return to their original, uncompressed state.<\/p>\n\n\n\n<p>This is where the powerful command \u201c<strong>Gunzip<\/strong>\u201d steps in. It acts like a digital magician, letting you effortlessly restore files and directories with extensions like&nbsp;<code>\u201c.gz\u201d<\/code>&nbsp;or&nbsp;<code>\u201c.z\u201d<\/code>&nbsp;to their primary state with the previous file size and format.<\/p>\n\n\n\n<p><strong>Quick Note:<\/strong> Gzip is a widely used utility employed to compress files, directories, tar archives, and even websites effectively. Think of it as a clever way to neatly pack your clothes in a suitcase before a trip \u2013 it\u2019s all about saving space in the most efficient way possible.<\/p>\n\n\n\n<p>Let\u2019s dive into this article, where we\u2019ll delve into the usage of the \u201c<strong>gunzip<\/strong>\u201d command with examples in Linux.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>1. Use of the \u201cgunzip\u201d Command in Linux<\/strong><\/h2>\n\n\n\n<p><strong>Gunzip<\/strong>&nbsp;is a command-line utility designed for decompressing files that have been compressed using the GNU Zip (gzip) compression algorithm. It efficiently restores files with suffixes, such as,&nbsp;<code>\u201c-gz\u201d<\/code>,&nbsp;<code>\u201c.gz\u201d<\/code>,&nbsp;<code>\u201c.z\u201d<\/code>,&nbsp;<code>\u201c.taz\u201d<\/code>,&nbsp;<code>\u201c.tgz\u201d<\/code>,&nbsp;<code>\u201c_z\u201d<\/code>,&nbsp;<code>\u201c-z\u201d<\/code>, or&nbsp;<code>\u201c.Z\u201d<\/code>&nbsp;back to their initial\/actual forms.<\/p>\n\n\n\n<p>During this process, the compressed file is seamlessly replaced with its uncompressed version. While&nbsp;<strong>Gunzip<\/strong>&nbsp;can even compress a file or directory, it is primarily renowned for its proficiency in decompression tasks.<\/p>\n\n\n\n<p>Let\u2019s discuss the syntax of&nbsp;<strong>gunzip<\/strong>&nbsp;command.<\/p>\n\n\n\n<p>$ gunzip [OPTION]&#8230; [FILE]&#8230;<\/p>\n\n\n\n<p>The syntax of the \u201c<strong>gunzip<\/strong>\u201d command has two parts:&nbsp;<strong>Option<\/strong>&nbsp;and&nbsp;<strong>File<\/strong>.<\/p>\n\n\n\n<p>The&nbsp;<strong>Option\/Flag<\/strong>&nbsp;is used to change the conduct of the command whereas&nbsp;<strong>File<\/strong>&nbsp;is the representation of the input files that need to be decompressed. The&nbsp;<strong>flag<\/strong>&nbsp;or&nbsp;<strong>option<\/strong>&nbsp;comes with a hyphen after the \u201c<strong>gunzip<\/strong>\u201d command.<\/p>\n\n\n\n<p>Run the&nbsp;<code>'gunzip -h'<\/code>&nbsp;command in your terminal to view the available options of the \u2018<strong>gunzip<\/strong>\u2018 command along with their explanations:<\/p>\n\n\n\n<p>$ gunzip -h<\/p>\n\n\n\n<p>These flags make it easy for a Linux user to perform compression and decompression in different cases.<\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_9148\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/08\/Gunzip-Command-Help.png\" alt=\"Gunzip Command Help\" class=\"wp-image-9148\"\/><figcaption class=\"wp-element-caption\">Gunzip Command Help<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>2. Why Do We Use Gunzip?<\/strong><\/h2>\n\n\n\n<p>Let\u2019s discuss a few of the reasons why Linux users prefer the \u201c<strong>gunzip<\/strong>\u201d command for decompressing files and directories:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The&nbsp;<strong>Gzip<\/strong>&nbsp;compression is a widely used and standardized compression format, making it compatible across different systems and platforms.<\/li>\n\n\n\n<li>The \u201c<strong>gunzip<\/strong>\u201d is used to decompress files that have been compressed using the&nbsp;<strong>gzip<\/strong>&nbsp;compression algorithm, which reduces the file size, making it more efficient for storage and data transfer.<\/li>\n\n\n\n<li>The compressed files are smaller in size, which means they can be transferred over networks more quickly.<\/li>\n\n\n\n<li>The compression not only saves space but also helps identify data corruption during transfer.<\/li>\n\n\n\n<li>The \u201c<strong>gunzip<\/strong>\u201d command proves to be very flexible due to the variety of flags that it offers.<\/li>\n\n\n\n<li>It can be integrated with many other Linux tools like&nbsp;<strong>tar<\/strong>&nbsp;etc, hence making it more convenient to use.<\/li>\n\n\n\n<li>The \u201c<strong>gunzip<\/strong>\u201d simplicity and consistent behavior make it ideal for scripting and automation purposes. Linux users often employ it within scripts and automated workflows to efficiently manage decompression tasks.<\/li>\n<\/ul>\n\n\n\n<p>Moving ahead, now we will discuss some examples of the&nbsp;<strong>gunzip<\/strong>&nbsp;command to understand its usage.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>3. How to Unzip (Open) Gz File<\/strong><\/h2>\n\n\n\n<p>At times when you need to&nbsp;<strong>unzip<\/strong>&nbsp;a single file, just execute the command provided below:<\/p>\n\n\n\n<p>$ gunzip singleFile.gz<\/p>\n\n\n\n<p>This will decompress the \u201c<strong>singleFile.gz<\/strong>\u201d file and restore the original file named \u201c<strong>singleFile<\/strong>\u201d. To verify if your file is decompressed, simply execute the \u201c<strong>ls<\/strong>\u201d command.<\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_9150\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/08\/Extract-Gz-File-Linux.png\" alt=\"Extract Gz File Linux\" class=\"wp-image-9150\"\/><figcaption class=\"wp-element-caption\">Extract Gz File Linux<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>4. How to Extract Multiple Gzip Files<\/strong><\/h2>\n\n\n\n<p>At times, you may need to decompress multiple files all at once by specifying the names of the&nbsp;<code>.gz<\/code>&nbsp;files you intend to decompress.<\/p>\n\n\n\n<p>$ gunzip multiFile1.gz multiFile2.gz multiFile3.gz<\/p>\n\n\n\n<p>This will decompress all three files (\u201c<strong>multiFile1.gz<\/strong>\u201d, \u201c<strong>multiFile2.gz<\/strong>\u201d, \u201c<strong>multiFile3.gz<\/strong>\u201d) and bring them to their previous corresponding decompressed states (\u201c<strong>multiFile1<\/strong>\u201d, \u201c<strong>multiFile2<\/strong>\u201d, \u201c<strong>multiFile3<\/strong>\u201d).<\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_9151\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/08\/Extract-Multiple-Gz-Files-Linux.png\" alt=\"Extract Multiple Gz Files in Linux\" class=\"wp-image-9151\"\/><figcaption class=\"wp-element-caption\">Extract Multiple Gz Files in Linux<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>5. Force Decompress a Gz File<\/strong><\/h2>\n\n\n\n<p>Sometimes, you may need to decompress a file while a decompressed file of the same name already exists in the directory. In such cases, a warning about file overwriting can arise.<\/p>\n\n\n\n<p>To address this situation, the \u201c<strong>gunzip<\/strong>\u201d command provides the&nbsp;<code>\"-f\"<\/code>&nbsp;or&nbsp;<code>\"--force\"<\/code>&nbsp;flag, which empowers you to forcefully decompress the file with a&nbsp;<code>\".gz\"<\/code>&nbsp;extension.<\/p>\n\n\n\n<p><strong>Note<\/strong>: The default behavior of the \u201c<strong>gunzip<\/strong>\u201d command is to replace the actual file. If you require to preserve\/retain the actual file intact, you can combine the&nbsp;<code>\"-f\"<\/code>&nbsp;and&nbsp;<code>\"-k\"<\/code>&nbsp;flags.<\/p>\n\n\n\n<p>For instance, to forcefully decompress the file \u201c<strong>forceFile.gz<\/strong>\u201d within a directory containing a file named \u201c<strong>forceFile<\/strong>\u201c, you can execute the mentioned command:<\/p>\n\n\n\n<p>$ gunzip -f forceFile.gz<\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_9152\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/08\/Force-Decompress-Gz-File.png\" alt=\"Force Decompress Gz File\" class=\"wp-image-9152\"\/><figcaption class=\"wp-element-caption\">Force Decompress Gz File<\/figcaption><\/figure>\n\n\n\n<p>This command will effectively decompress the file \u201c<strong>forceFile.gz<\/strong>\u201d to \u201c<strong>forceFile<\/strong>\u201c, even if an existing \u201c<strong>forceFile<\/strong>\u201d file is present on your system.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>6. How to Unzip a Gz File to a Directory<\/strong><\/h2>\n\n\n\n<p>Until now you must have noticed that all the decompressed files resided in the same directory where their corresponding compressed files were located. This might have sparked the question:<\/p>\n\n\n\n<p>\u201cCan we decompress files directly into another directory or location?\u201d The answer is yes, we can simply use the&nbsp;<code>\u201c-d\u201d<\/code>&nbsp;flag to decompress a file in another directory.<\/p>\n\n\n\n<p>To do so, simply specify the path of the directory where you want to decompress the desired file, followed by the file\u2019s name after the&nbsp;<strong>\u201c-d\u201d<\/strong>&nbsp;flag, as demonstrated below:<\/p>\n\n\n\n<p>$ gunzip -d ~\/to\/Ubuntu\/Mint\/directory\/file.gz<\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_9155\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/08\/Unzip-Gz-File-to-Directory.png\" alt=\"Unzip Gz File to Directory\" class=\"wp-image-9155\"\/><figcaption class=\"wp-element-caption\">Unzip Gz File to Directory<\/figcaption><\/figure>\n\n\n\n<p>This will decompress the file \u201c<strong>file.gz<\/strong>\u201d in the \u201c<strong>~\/to\/Ubuntu\/Mint\/directory<\/strong>\u201d directory.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>7. How to Unzip Gzip File While Keeping Original File<\/strong><\/h2>\n\n\n\n<p>Consider a scenario where you want to send a compressed file to your friend and keep the decompressed file for yourself or vice versa. In either case, the objective is to retain both versions of the file in your system. For this purpose, the \u201c<strong>gunzip<\/strong>\u201d command offers the&nbsp;<code>\"-k\"<\/code>&nbsp;option.<\/p>\n\n\n\n<p>To implement this approach, run the command stated below, which will decompress the files \u201c<strong>originalFile1.gz<\/strong>\u201d and \u201c<strong>originalFile2.gz<\/strong>\u201c, simultaneously redirecting the decompressed output to new files named \u201c<strong>originalFile1<\/strong>\u201d and \u201c<strong>originalFile2<\/strong>\u201c, all while retaining the compressed versions of the files:<\/p>\n\n\n\n<p>$ gunzip -k originalFile1.gz originalFile2.gz<\/p>\n\n\n\n<p>Executing this command will effectively decompress the specified files, creating new decompressed versions while retaining the original compressed files intact. To confirm the change, display all the files in the current directory.<\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_9156\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/08\/Unzip-Gzip-File-by-Keeping-Original-File.png\" alt=\"Unzip Gzip File by Keeping Original File\" class=\"wp-image-9156\"\/><figcaption class=\"wp-element-caption\">Unzip Gzip File by Keeping Original File<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>8. How to Unzip Gzip File to Standard Output<\/strong><\/h2>\n\n\n\n<p>Want to see the content of a compressed file but don\u2019t want to decompress it? Well, no worries you can simply use the&nbsp;<code>\u201c-c\u201d<\/code>&nbsp;flag to view the text of the compressed file:<\/p>\n\n\n\n<p>$ gunzip -c ubuntuMintFile.gz<\/p>\n\n\n\n<p>This command will display the textual content of the file \u201c<strong>ubuntuMintFile.gz<\/strong>\u201d.<\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_9157\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/08\/View-Gzip-File-Contents.png\" alt=\"View Gzip File Contents\" class=\"wp-image-9157\"\/><figcaption class=\"wp-element-caption\">View Gzip File Contents<\/figcaption><\/figure>\n\n\n\n<p>In the output below you can see that you get the same output by using the&nbsp;<code>\u201c-c\u201d<\/code>&nbsp;flag and by unzipping the file first and then using the&nbsp;<a href=\"https:\/\/www.ubuntumint.com\/view-contents-of-file-in-linux\/\" target=\"_blank\" rel=\"noreferrer noopener\">cat command<\/a>&nbsp;to read data from a file and display it on the console as output.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>9. How to Check the Information of Gzip File<\/strong><\/h2>\n\n\n\n<p>Being a Linux user, you might face a situation where you\u2019ve compressed a file and you want to know the details about it. Ideally, you should be decompressing it before and then you might be able to get its details.<\/p>\n\n\n\n<p>The \u201c<strong>gunzip<\/strong>\u201d command provides a&nbsp;<code>\u201c-l\u201d<\/code>&nbsp;flag which displays the information about the compressed file without necessitating its decompression. This information might be the size of the original file, the size of a compressed file, the name of the actual file, and the ratio of compression.<\/p>\n\n\n\n<p>Let\u2019s try it out by using a compressed file \u201c<strong>ubuntuMintFile.gz<\/strong>\u201d:<\/p>\n\n\n\n<p>$ gunzip -l ubuntuMintFile.gz<\/p>\n\n\n\n<p>This will display comprehensive information about the \u201c<strong>ubuntuMintFile<\/strong>\u201d file.<\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_9158\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/08\/View-Gzip-File-Info.png\" alt=\"View Gzip File Info\" class=\"wp-image-9158\"\/><figcaption class=\"wp-element-caption\">View Gzip File Info<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>10. How to Decompress a Gzip File with Max Compression<\/strong><\/h2>\n\n\n\n<p>There are instances when you\u2019ll encounter a situation where the quality of the decompressed file takes precedence over the time consumed by the decompression process. In such instances, you can use the&nbsp;<code>\u201c-9\u201d<\/code>&nbsp;flag of the \u201c<strong>gunzip<\/strong>\u201d to achieve a higher-quality decompression, as demonstrated below:<\/p>\n\n\n\n<p>$ gunzip -9 betterFile.gz<\/p>\n\n\n\n<p>This command decompresses the file \u201c<strong>betterFile.gz<\/strong>\u201d in better quality but obviously will consume more time in the decompression process.<\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_9159\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/08\/Decompress-Gzip-File-Better.png\" alt=\"Decompress Gzip File Better\" class=\"wp-image-9159\"\/><figcaption class=\"wp-element-caption\">Decompress Gzip File Better<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>11. How to Decompress a Gzip File Faster<\/strong><\/h2>\n\n\n\n<p>Likewise, you can even prefer speed over quality while uncompressing a file or directory. In this case, use the&nbsp;<code>\u201c-1\u201d<\/code>&nbsp;option followed by the filename that is to be decompressed.<\/p>\n\n\n\n<p>$ gunzip -1 fasterFile.gz<\/p>\n\n\n\n<p>This command extracts the file \u201c<strong>fasterFile.gz<\/strong>\u201d in a lesser time with a considerable speed.<\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_9160\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/08\/Decompress-Gzip-File-Faster.png\" alt=\"Decompress Gzip File Faster\" class=\"wp-image-9160\"\/><figcaption class=\"wp-element-caption\">Decompress Gzip File Faster<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>12. How to View Gzip Decompress Process<\/strong><\/h2>\n\n\n\n<p>To decompress a file while receiving detailed feedback, the \u201c<strong>gunzip<\/strong>\u201d command provides the useful&nbsp;<code>\u201c-v\u201d<\/code>&nbsp;flag that displays the progress and details of the decompression process.<\/p>\n\n\n\n<p>$ gunzip -v verboseFile.gz<\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_9161\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/08\/View-Decompress-Gzip-Progress.png\" alt=\"View Unzip Gzip File Progress\" class=\"wp-image-9161\"\/><figcaption class=\"wp-element-caption\">View Unzip Gzip File Progress<\/figcaption><\/figure>\n\n\n\n<h5 class=\"wp-block-heading\">Conclusion<\/h5>\n\n\n\n<p>The \u201c<strong>gunzip<\/strong>\u201d command is one of the best algorithms used by Linux enthusiasts for file decompression. This guide covered various commands for decompressing files and directories using the \u201c<strong>gunzip<\/strong>\u201d utility that are compressed by the \u201c<strong>gzip<\/strong>\u201d command.<\/p>\n\n\n\n<p><a href=\"https:\/\/www.ubuntumint.com\/unzip-gzip-file-in-linux\/\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>File compression is a common practice in Linux, where its users shrink files and directories using tools like&nbsp;Gzip&nbsp;to free up storage space and increase their system\u2019s performance. This compression technique also smooths out the process of sending files across networks \u2013 fast and efficient. But here\u2019s the twist: when you need to use or change &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2023\/11\/01\/how-to-uncompress-a-gz-file-in-linux-with-gunzip-command\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Uncompress a \u2018.gz\u2019 File in Linux With Gunzip Command.&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-16940","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/16940","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=16940"}],"version-history":[{"count":3,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/16940\/revisions"}],"predecessor-version":[{"id":16946,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/16940\/revisions\/16946"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=16940"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=16940"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=16940"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}