{"id":28878,"date":"2021-07-24T21:00:50","date_gmt":"2021-07-24T21:00:50","guid":{"rendered":"https:\/\/linuxiac.com\/?p=28878"},"modified":"2023-10-22T11:01:30","modified_gmt":"2023-10-22T11:01:30","slug":"how-to-untar-tar-gz-file","status":"publish","type":"post","link":"https:\/\/linuxiac.com\/how-to-untar-tar-gz-file\/","title":{"rendered":"How to Extract tar.gz File in Linux by Using the Command Line"},"content":{"rendered":"\n<p>Many of the downloadable Linux\/Unix files found on the internet are compressed using a&nbsp;<code>tar.gz<\/code>&nbsp;format. Therefore, knowing how to open or untar <code>tar.gz<\/code> files is very useful.<\/p>\n\n\n\n<p>The name &#8220;Tar&#8221; stands for &#8220;Tape Archiver&#8221; because it was used to place data on storage tapes when tar was invented. A <code>.tar.gz<\/code> file is nothing but an archive. The <code>tar<\/code> program takes one or more files and &#8220;wraps&#8221; them into a self-contained file.<\/p>\n\n\n\n<p>To untar <code>tar.gz<\/code> files means to extract the contents of the <code>tar<\/code> file (also known as a tarball). Additionally, if you want to learn how to create&nbsp;<code>tar.gz<\/code>&nbsp;files in Linux, check out our excellent guide, &#8220;<a href=\"https:\/\/linuxiac.com\/how-to-create-tar-gz-archive-using-tar-command-on-linux\/\">How to Create tar.gz Archive Using the tar Command on Linux<\/a>.&#8221;<\/p>\n\n\n\n<p>People new to the <code>.tar<\/code> format usually equate it to a <code>.zip<\/code>&nbsp;archive, but a tar archive is not&nbsp;compressed. Tar&nbsp;collected all the files into one package, but the files&nbsp;can be compressed with separate utilities.<\/p>\n\n\n\n<p>The most often used algorithm for compressing tar files is <a href=\"https:\/\/www.gnu.org\/software\/gzip\/\" target=\"_blank\" rel=\"noreferrer noopener\">Gzip<\/a>. By convention, the name of a <code>tar<\/code> archive compressed with&nbsp;<code>gzip<\/code>&nbsp;becomes&nbsp;<code>.tar.gz<\/code>&nbsp;or&nbsp;<code>.tgz<\/code>.<\/p>\n\n\n\n<p>To put it simply: a file that ends in&nbsp;<code>.tar.gz<\/code>&nbsp;is just a&nbsp;<code>.tar<\/code>&nbsp;archive compressed with <code>gzip<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-how-to-extract-a-tar-gz-file\">How to Extract a tar.gz File<\/h2>\n\n\n\n<p>Most Linux distributions come with the&nbsp;<code>tar<\/code>&nbsp;command pre-installed by default.<\/p>\n\n\n\n<p>To untar <code>tar.gz<\/code> file, enter the following:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code lang=\"bash\" class=\"hljs language-css language-bash\"><span class=\"hljs-selector-tag\">tar<\/span> <span class=\"hljs-selector-tag\">xvzf<\/span> <span class=\"hljs-selector-tag\">file<\/span><span class=\"hljs-selector-class\">.tar<\/span><span class=\"hljs-selector-class\">.gz<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Let\u2019s break down this syntax. Here is what each parameter in that command means:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>x<\/code>: This option tells&nbsp;tar&nbsp;to extract the files.<\/li>\n\n\n\n<li><code>v<\/code>: Verbose output shows you all the files being extracted.<\/li>\n\n\n\n<li><code>z<\/code>: Tells tar to decompress the archive using gzip.<\/li>\n\n\n\n<li><code>f<\/code>: This must be the last flag of the command. It tells tar the name and path of the compressed file.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How to Extract a tar.gz File to a Different Directory<\/h2>\n\n\n\n<p>To uncompress the <code>tar.gz<\/code> file and put resulted files in a different directory, say <code>\/tmp\/archive<\/code>, you need to add a <code>-C<\/code> option at the end of the command:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code lang=\"bash\" class=\"hljs language-bash\">tar xvzf file.tar.gz -C \/tmp\/archive<\/code><\/span><\/pre>\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>The&nbsp;<code>-C<\/code>&nbsp;option is used to specify a different directory other than the current working directory.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">View a List of Files within an Archive<\/h2>\n\n\n\n<p>Sometimes you need to view the content of a tar file as it collects many files and ensures if a specific file is present.&nbsp;<\/p>\n\n\n\n<p>To view a detailed table of contents for archive called <code>data.tar.gz<\/code>, use the following syntax:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code lang=\"bash\" class=\"hljs language-css language-bash\"><span class=\"hljs-selector-tag\">tar<\/span> <span class=\"hljs-selector-tag\">tf<\/span> <span class=\"hljs-selector-tag\">data<\/span><span class=\"hljs-selector-class\">.tar<\/span><span class=\"hljs-selector-class\">.gz<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><a href=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2021\/07\/untar-tar-gz-file.png\"><img decoding=\"async\" width=\"922\" height=\"296\" src=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2021\/07\/untar-tar-gz-file.png\" alt=\"View a List of Files within tar.gz Archive\" class=\"wp-image-43489\" srcset=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2021\/07\/untar-tar-gz-file.png 922w, https:\/\/linuxiac.com\/wp-content\/uploads\/2021\/07\/untar-tar-gz-file-380x122.png 380w, https:\/\/linuxiac.com\/wp-content\/uploads\/2021\/07\/untar-tar-gz-file-768x247.png 768w\" sizes=\"(max-width: 922px) 100vw, 922px\" \/><\/a><\/figure>\n\n\n\n<p>Where:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>t<\/code>: Used to list the content of the <code>tar<\/code> file<\/li>\n\n\n\n<li><code>f<\/code>: Commanding the utility to use the file mentioned in the following argument<\/li>\n<\/ul>\n\n\n\n<p>You can also get detailed standard output by using the <code>v<\/code> (verbose) option.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code lang=\"basic\" class=\"hljs language-css language-basic\"><span class=\"hljs-selector-tag\">tar<\/span> <span class=\"hljs-selector-tag\">tvf<\/span> <span class=\"hljs-selector-tag\">data<\/span><span class=\"hljs-selector-class\">.tar<\/span><span class=\"hljs-selector-class\">.gz<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><a href=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2021\/07\/untar-tar-gz-file2.png\"><img decoding=\"async\" width=\"919\" height=\"292\" src=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2021\/07\/untar-tar-gz-file2.png\" alt=\"How to Extract tar.gz File in Linux by Using the Command Line\" class=\"wp-image-43492\" srcset=\"https:\/\/linuxiac.com\/wp-content\/uploads\/2021\/07\/untar-tar-gz-file2.png 919w, https:\/\/linuxiac.com\/wp-content\/uploads\/2021\/07\/untar-tar-gz-file2-380x121.png 380w, https:\/\/linuxiac.com\/wp-content\/uploads\/2021\/07\/untar-tar-gz-file2-768x244.png 768w\" sizes=\"(max-width: 919px) 100vw, 919px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<p>Now you know how to untar a <code>tar.gz<\/code> <a href=\"https:\/\/linuxiac.com\/linux-file-system-types-explained-which-one-should-you-use\/\">file in Linux<\/a>. Perhaps you might also be interested in learning <a href=\"https:\/\/linuxiac.com\/how-to-unzip-in-linux\/\">how to unzip files in Linux<\/a>.<\/p>\n\n\n\n<p>For more about&nbsp;<code>tar<\/code>&nbsp;command in Linux, consult its&nbsp;<a href=\"https:\/\/man7.org\/linux\/man-pages\/man1\/tar.1.html\" target=\"_blank\" rel=\"noreferrer noopener\">manual page<\/a>.<\/p>\n\n\n\n<p>If you find this article helpful or have additional ideas, please use the comment box below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article will learn how to extract\/untar tar.gz files in Linux systems through the command line using the tar command.<\/p>\n","protected":false},"author":10,"featured_media":28977,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,4417],"tags":[5481,1484,4161,4164],"class_list":["post-28878","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tips","category-linux-knowledge","tag-archiver","tag-commands","tag-tar","tag-untar"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":6},"post_title_panel":"","has_hero_section":"default","98840684be206178a1eed57369ab653e":"","hero_section":"type-2","hero_elements":[{"id":"custom_title","enabled":true,"heading_tag":"h1","title":"Home","__id":"GDq0vnjjOuphXzwpYSODy"},{"id":"custom_description","enabled":false,"description_visibility":{"desktop":true,"tablet":true,"mobile":false},"__id":"Xpw4xg7jJ-nl8ezfIvOxW"},{"id":"custom_meta","enabled":true,"meta_elements":[{"id":"author","enabled":true,"label":"By","has_author_avatar":"yes","avatar_size":50,"__id":"CUIN61qS-14USy2IgrGe3"},{"id":"post_date","enabled":false,"label":"On","date_format_source":"default","date_format":"M j, Y","__id":"OqgNK_VoLpLNLa4GwyS5l"},{"id":"updated_date","enabled":true,"label":"Updated","date_format_source":"default","date_format":"M j, Y","__id":"yXuBXhAyl3IuNIkZ0KuAG"},{"id":"categories","enabled":false,"label":"In","style":"simple","__id":"gUsZT2WvANtQbx1Ds1RTD"},{"id":"comments","enabled":true,"__id":"qBG9j8fYm0xpKdLHm8RIz"}],"page_meta_elements":{"joined":true,"articles_count":true,"comments":true},"__id":"xLtG-oD9dyxuYb4CJOU_0","meta_type":"label","meta_divider":"circle"},{"id":"breadcrumbs","enabled":false,"__id":"K8xP789sNjMg-ZOnA7km_"}],"990da89fb07ad61a7b3f71dfd103a099":"","hero_alignment1":"CT_CSS_SKIP_RULE","hero_margin":40,"hero_alignment2":"center","hero_vertical_alignment":"center","920d5375c365fc05a70889e47a243457":"","hero_structure":"normal","582e089c4076ad5d9227b9f76c8c4dc8":"","page_title_bg_type":"custom_image","custom_hero_background":{"attachment_id":43495,"url":"https:\/\/linuxiac.com\/wp-content\/uploads\/2021\/07\/untar-tar-gz-header-1024x226.png"},"page_title_image_size":"full","parallax":{"desktop":false,"tablet":false,"mobile":false},"82e476c3e012237de837eb6c677a998a":"","hero_height":"250px","pageTitleFont":{"family":"Default","variation":"Default","size":{"desktop":"2.8em","tablet":"2.8em","mobile":"2.8em","__changed":[]},"line-height":"CT_CSS_SKIP_RULE","letter-spacing":"CT_CSS_SKIP_RULE","text-transform":"CT_CSS_SKIP_RULE","text-decoration":"CT_CSS_SKIP_RULE"},"pageTitleFontColor":{"default":{"color":"CT_CSS_SKIP_RULEDEFAULT"}},"pageMetaFont":{"family":"Default","variation":"n6","size":"12px","line-height":"1.3","letter-spacing":"CT_CSS_SKIP_RULE","text-transform":"uppercase","text-decoration":"CT_CSS_SKIP_RULE"},"pageMetaFontColor":{"default":{"color":"CT_CSS_SKIP_RULEDEFAULT"},"hover":{"color":"CT_CSS_SKIP_RULEDEFAULT"}},"page_meta_button_type_font_colors":{"default":{"color":"CT_CSS_SKIP_RULEDEFAULT"},"hover":{"color":"CT_CSS_SKIP_RULEDEFAULT"}},"page_meta_button_type_background_colors":{"default":{"color":"CT_CSS_SKIP_RULEDEFAULT"},"hover":{"color":"CT_CSS_SKIP_RULEDEFAULT"}},"pageExcerptFont":{"family":"Default","variation":"Default","size":"CT_CSS_SKIP_RULE","line-height":"CT_CSS_SKIP_RULE","letter-spacing":"CT_CSS_SKIP_RULE","text-transform":"CT_CSS_SKIP_RULE","text-decoration":"CT_CSS_SKIP_RULE"},"pageExcerptColor":{"default":{"color":"CT_CSS_SKIP_RULEDEFAULT"}},"breadcrumbsFont":{"family":"Default","variation":"Default","size":"CT_CSS_SKIP_RULE","line-height":"CT_CSS_SKIP_RULE","letter-spacing":"CT_CSS_SKIP_RULE","text-transform":"CT_CSS_SKIP_RULE","text-decoration":"CT_CSS_SKIP_RULE"},"breadcrumbsFontColor":{"default":{"color":"CT_CSS_SKIP_RULEDEFAULT"},"initial":{"color":"CT_CSS_SKIP_RULEDEFAULT"},"hover":{"color":"CT_CSS_SKIP_RULEDEFAULT"}},"pageTitleOverlay":{"background_type":"color","background_pattern":"type-1","background_image":{"attachment_id":null,"x":0,"y":0},"gradient":"linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)","background_repeat":"repeat","background_size":"auto","background_attachment":"scroll","patternColor":{"default":{"color":"#e5e7ea"}},"overlayColor":{"default":{"color":"CT_CSS_SKIP_RULE"}},"backgroundColor":{"default":{"color":"CT_CSS_SKIP_RULE"}}},"pageTitleBackground":{"background_type":"color","background_pattern":"type-1","background_image":{"attachment_id":null,"x":0,"y":0},"gradient":"linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)","background_repeat":"repeat","background_size":"auto","background_attachment":"scroll","patternColor":{"default":{"color":"#e5e7ea"}},"overlayColor":{"default":{"color":"CT_CSS_SKIP_RULE"}},"backgroundColor":{"default":{"color":"var(--theme-palette-color-6)"}}},"pageTitlePadding":{"top":"50px","bottom":"50px","left":"auto","right":"auto","linked":true},"7b9a0f849adfc100a4280b0a32aace90":"","page_structure_type":"default","544b60ef2f5cf27545e9623abea5249a":"","content_style_source":"inherit","content_style":"wide","630195086d7d2ff9b72892a5cf094c38":"","vertical_spacing_source":"inherit","content_area_spacing":"both","background":{"background_type":"color","background_pattern":"type-1","background_image":{"attachment_id":null,"x":0,"y":0},"gradient":"linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)","background_repeat":"repeat","background_size":"auto","background_attachment":"scroll","patternColor":{"default":{"color":"#e5e7ea"}},"overlayColor":{"default":{"color":"CT_CSS_SKIP_RULE"}},"backgroundColor":{"default":{"color":"CT_CSS_SKIP_RULE"}}},"content_background":{"background_type":"color","background_pattern":"type-1","background_image":{"attachment_id":null,"x":0,"y":0},"gradient":"linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)","background_repeat":"repeat","background_size":"auto","background_attachment":"scroll","patternColor":{"default":{"color":"#e5e7ea"}},"overlayColor":{"default":{"color":"CT_CSS_SKIP_RULE"}},"backgroundColor":{"default":{"color":"var(--theme-palette-color-8)"}}},"content_boxed_shadow":{"inherit":false,"blur":18,"spread":-6,"v_offset":12,"h_offset":0,"inset":false,"enable":true,"color":{"color":"rgba(34, 56, 101, 0.04)"}},"boxed_content_spacing":{"desktop":{"top":"40px","bottom":"40px","left":"40px","right":"40px","linked":true},"tablet":{"top":"35px","bottom":"35px","left":"35px","right":"35px","linked":true},"mobile":{"top":"20px","bottom":"20px","left":"20px","right":"20px","linked":true}},"content_boxed_radius":{"top":"3px","bottom":"3px","left":"3px","right":"3px","linked":true},"ba8a60822c24bbdeee6f6b0cdbb650f1":"","disable_featured_image":"no","disable_post_tags":"no","disable_share_box":"no","disable_author_box":"no","disable_posts_navigation":"no","disable_subscribe_form":"no","2285408a7f64be3674b68df7e9d6f85c":"","disable_related_posts":"no","disable_header":"no","disable_footer":"no","668c69dc5b69c5d3777d88d96814c191":"","header_footer_scripts_panel":"","header_scripts":"","183d702e8dabe22273b18d9807e28b64":"","header_after_body_scripts":"","88d4124305a6f244ceb535f2c3213cd8":"","footer_scripts":""},"_links":{"self":[{"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/posts\/28878","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/comments?post=28878"}],"version-history":[{"count":0,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/posts\/28878\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/media\/28977"}],"wp:attachment":[{"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/media?parent=28878"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/categories?post=28878"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxiac.com\/wp-json\/wp\/v2\/tags?post=28878"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}