{"id":22204,"date":"2023-10-01T16:43:27","date_gmt":"2023-10-01T16:43:27","guid":{"rendered":"https:\/\/linuxways.net\/?p=22204"},"modified":"2023-10-01T16:44:16","modified_gmt":"2023-10-01T16:44:16","slug":"how-to-extract-unzip-tar-gz-files-from-linux-ubuntu-commands","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-extract-unzip-tar-gz-files-from-linux-ubuntu-commands\/","title":{"rendered":"How to Extract\/Unzip tar.gz Files from Linux\/Ubuntu Commands?"},"content":{"rendered":"<p>Software packages are available to download in the form of <strong>compressed archives <\/strong>from the software developer\u2019s website. These archives are <strong>extracted<\/strong> before the installation process. There are many compressed archives like .deb, .rpm, tar.gz, etc. among which, <strong>tar.gz i<\/strong>s widely used for software distribution. The compression and extraction of <strong>tar.gz <\/strong>archives is supported by the command line tool <strong>tar <\/strong>in Linux\/Ubuntu.<\/p>\n<p>This article will discuss different scenarios of extracting the tar.gz archive on Linux\/Ubuntu 22.04 LTS systems.<\/p>\n<h2><a id=\"post-22204-_vwi4ezl9toa3\"><\/a>How to Extract\/Unzip tar.gz Files from Linux\/Ubuntu Commands?<\/h2>\n<p>The \u201c<strong>tar.gz<\/strong>\u201d is a compressed archive file format for Linux systems that uses the \u201cgzip\u201d compression algorithm. \u201c.tar.gz\u201d archives can be created by <a href=\"https:\/\/linuxways.net\/de\/create-tar-file-ubuntu\/\">How to Create a Tar File in Linux\/Ubuntu<\/a>? Consider that we have an archive \u201carchive.tar.gz\u201d in the \u201cSampleDirector1\u201d directory. In the following sections, three scenarios of the extraction files from archive.tar.gz will be discussed:<\/p>\n<ul>\n<li>Scenario 1: Extract\/Unzip \u201c.tar.gz\u201d Files in Current Working Directory.<\/li>\n<li>Scenario 2: Extract\/Unzip \u201c.tar.gz\u201d Files to a Specific Directory.<\/li>\n<li>Scenario 3: Extract\/Unzip Specific Files from a \u201c.tar.gz\u201d Archive.<\/li>\n<\/ul>\n<h2><a id=\"post-22204-_66dmbaiwruy4\"><\/a>Scenario 1: Extract\/Unzip \u201c.tar.gz\u201d Files in the Current Working Directory<\/h2>\n<p>The archive \u201cArchive.tar.gz\u201d can be extracted in the same directory by the following command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">tar<\/span> xzf archive.tar.gz<\/div><\/div>\n<p>The above command comprises of:<\/p>\n<ul>\n<li>tar: tar command line tool<\/li>\n<li>x: extract files from an archive.<\/li>\n<li>z: constructs the compressed\/extracted archive using \u201cgzip\u201d.<\/li>\n<li>f: Read the archive -archive.tar.gz (name of the archive file)<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"367\" class=\"wp-image-22215\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-1.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-1.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-1-300x54.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-1-1024x184.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-1-768x138.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-1-1536x275.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>We can verify the extraction of the \u201carchive.tar.gz\u201d archive by:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"476\" class=\"wp-image-22218\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-2.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-2.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-2-300x70.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-2-1024x238.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-2-768x179.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-2-1536x357.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>The above image shows that archive.tar.gz is successfully extracted to the \u201cSampleDirectory1\u201d directory.<\/p>\n<h2><a id=\"post-22204-_zb454p73l2tu\"><\/a>Scenario 2: Extract\/Unzip \u201c.tar.gz\u201d Files to a Specific Directory<\/h2>\n<p>If we would like to extract the \u201carchive.tar.gz\u201d archive in a specific directory, i.e., in the \u201cOthers\u201d directory inside the \u201cDownloads\u201d directory, we can run the following command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">tar<\/span> xzf archive.tar.gz <span class=\"re5\">-C<\/span> <span class=\"sy0\">\/<\/span>home<span class=\"sy0\">\/<\/span>linuxuser<span class=\"sy0\">\/<\/span>Downloads<span class=\"sy0\">\/<\/span>Others<span class=\"sy0\">\/<\/span><\/div><\/div>\n<p>The above command comprises of:<\/p>\n<ul>\n<li>-C: Extract the \u201ctar.gz\u201d files in a specific directory.<\/li>\n<li>\/home\/linuxuser\/Downloads\/Others\/: path where the files will be extracted.<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"154\" class=\"wp-image-22222\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-3.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-3.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-3-300x23.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-3-1024x77.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-3-768x58.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-3-1536x116.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>We can verify the extraction of the \u201carchive.tar.gz\u201d archive by navigating to the specified path:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\">$ <span class=\"kw3\">cd<\/span> <span class=\"sy0\">\/<\/span>home<span class=\"sy0\">\/<\/span>linuxuser<span class=\"sy0\">\/<\/span>Downloads<span class=\"sy0\">\/<\/span>Others<span class=\"sy0\">\/<\/span><br \/>\n<br \/>\n$ <span class=\"kw2\">ls<\/span> <span class=\"re5\">-l<\/span><\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"547\" class=\"wp-image-22234\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-4.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-4.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-4-300x80.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-4-1024x274.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-4-768x205.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-4-1536x410.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>The above image shows that archive.tar.gz is successfully extracted to the \u201cOthers\u201d directory (home\/linuxuser\/Downloads\/Others) from the \u201cSampleDirector1\u201d directory.<\/p>\n<h1><\/h1>\n<h2><a id=\"post-22204-_l7yrku31gw1t\"><\/a>Scenario 3: Extract\/Unzip Specific Files from a \u201c.tar.gz\u201d Archive<\/h2>\n<p>There can be situations where all the files compressed in the archive are not required and only a file or few files are required. \u201cTar\u201d allows the extraction of a file or a few files. The following command will extract only File3.txt and File5.txt from archive.tar.gz:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">tar<\/span> xzvf archive.tar.gz File3.txt File5.txt<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"547\" class=\"wp-image-22242\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-5.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-5.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-5-300x80.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-5-1024x274.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-5-768x205.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-5-1536x410.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>In the above command, the <strong>v<\/strong> flag indicates verbose output.<\/p>\n<p>We can verify the extraction of specific files of the \u201carchive.tar.gz\u201d archive by:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">ls<\/span> <span class=\"re5\">-l<\/span><\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"322\" class=\"wp-image-22252\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-6.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-6.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-6-300x47.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-6-1024x161.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-6-768x121.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22204-6-1536x242.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>The above image shows that only File3.txt and File5.txt are successfully extracted to the \u201cSampleDirectory1\u201d directory.<\/p>\n<h2><a id=\"post-22204-_k4r3ojha6hv3\"><\/a>Conclusion<\/h2>\n<p>Tar.gz archives are extracted using the <strong>tar<\/strong> command line tool in either the current working directory or in a specific directory by using the \u201ctar xzf &lt;archive.tar.gz&gt;\u201d and \u201ctar xzf &lt;archive.tar.gz&gt; -C &lt;\/path&gt;\u201d commands respectively. Additionally, specific files can be extracted from the archive by running \u201ctar xzvf &lt;archive.tar.gz&gt; &lt;File.txt&gt;\u201d. This article discussed different scenarios of extracting the tar.gz archive on Linux\/Ubuntu 22.04 LTS systems.<\/p>","protected":false},"excerpt":{"rendered":"<p>Tar.gz archives are extracted either in the current working directory or in a specific directory. Additionally, specific file(s) can also be extracted.<\/p>","protected":false},"author":110,"featured_media":22342,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1049,2],"tags":[],"class_list":["post-22204","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-commands","category-ubuntu"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/22204","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/110"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=22204"}],"version-history":[{"count":1,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/22204\/revisions"}],"predecessor-version":[{"id":22360,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/22204\/revisions\/22360"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/22342"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=22204"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=22204"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=22204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}