{"id":18112,"date":"2022-08-13T18:14:16","date_gmt":"2022-08-13T18:14:16","guid":{"rendered":"https:\/\/linuxways.net\/?p=18112"},"modified":"2022-09-05T16:51:01","modified_gmt":"2022-09-05T16:51:01","slug":"unpack-tar-files-linux","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/linux-commands\/unpack-tar-files-linux\/","title":{"rendered":"How to Unpack Tar Files in Linux"},"content":{"rendered":"<p>When using Linux, you are guaranteed to see tar files, especially when downloading the open-source packages. Besides, creating tar compressed files is easy using the programs like <strong>gzip. <\/strong>Tar is meant for compressing magnetic tapes, and it stands for \u201c<strong>tape archive<\/strong>\u201d.<\/p>\n<p>Tar files support various compression such as gzip, which have the <strong>.tar.gz.<\/strong> If you are looking on how to unpack the tar files, this guide covers how to create tar files and the two ways of unpacking tar files in Linux.<\/p>\n<h2><strong>Working with Tar Command in Linux<\/strong><\/h2>\n<p>For most Linux distributions, the tar command comes preinstalled. You can confirm by checking its version, as in the following image:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"729\" height=\"186\" class=\"wp-image-18136\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-1.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-1.png 729w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-1-300x77.png 300w\" sizes=\"auto, (max-width: 729px) 100vw, 729px\" \/><\/p>\n<p>There are various options that you can use with tar. They include:<\/p>\n<p><strong>1. -x: <\/strong>Added to extract an archive.<\/p>\n<p><strong>2. -c: <\/strong>Creates an archive.<\/p>\n<p><strong>3. -v: <\/strong>Show details of the operation.<\/p>\n<p><strong>4. -f: <\/strong>Specifies an archive file name.<\/p>\n<p><strong>5. -t: <\/strong>Lists details of the archive.<\/p>\n<p>Those are the main options. We will see how to use them using the following examples:<\/p>\n<p>For this example, we will create an archive file using tar and then cover the two ways of unpacking it.<\/p>\n<p>To create an archive file, the syntax would be:<\/p>\n<pre>$ tar -cf [archive-file] file1 file2 file_n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"740\" height=\"167\" class=\"wp-image-18143\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-2.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-2.png 740w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-2-300x68.png 300w\" sizes=\"auto, (max-width: 740px) 100vw, 740px\" \/><\/p>\n<p>We created a \u201c.tar\u201d file. Next, let\u2019s create a \u201c.tar.gz\u201d using the gzip compression. The syntax would be:<\/p>\n<pre>$ tar -czvf [archive-name] file1 file2 file_n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"737\" height=\"197\" class=\"wp-image-18145\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-3.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-3.png 737w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-3-300x80.png 300w\" sizes=\"auto, (max-width: 737px) 100vw, 737px\" \/><\/p>\n<p>With our two archive files, we can unpack them using tar.<\/p>\n<h2><strong>How to Unpack Tar Files<\/strong><\/h2>\n<p>To extract the tar files, use the Command Line or the GUI.<\/p>\n<h3><strong>1. Extract Tar Files Using GUI<\/strong><\/h3>\n<p>The first thing is to use your file manager and navigate to where the tar archive is located. In our case, it is \/Desktop.<\/p>\n<p>Next, <strong>right-click <\/strong>the tar file that you wish to extract. You can either choose <strong>Extract Here <\/strong>to extract the contents of the tar file in the current directory or use the <strong>Extract To <\/strong>and specify where you want to extract the tar files.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1366\" height=\"768\" class=\"wp-image-18148\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-4.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-4.png 1366w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-4-300x169.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-4-1024x576.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-4-768x432.png 768w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/p>\n<p>Alternatively, you can double-click the tar archive which lists the contents inside it. From there, you can extract the tar by clicking the <strong>extract <\/strong>button at the top-left corner.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"620\" height=\"345\" class=\"wp-image-18149\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-5.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-5.png 620w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-5-300x167.png 300w\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" \/><\/p>\n<h3><strong>2. Extract Tar Files Using Command Line<\/strong><\/h3>\n<p>Unlike GUI, the command line gives you more flexibility regarding what you can do when unpacking tar files.<\/p>\n<p><strong>Option 1. <\/strong>To extract the tar file in the same directory, use the <strong>-xf <\/strong>flags followed by the tar file.<\/p>\n<p>The command would be:<\/p>\n<pre>$ tar -xf linuxhint.tar<\/pre>\n<p>Replace the tar file with the one you are using for your case.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"735\" height=\"150\" class=\"wp-image-18150\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-6.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-6.png 735w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-6-300x61.png 300w\" sizes=\"auto, (max-width: 735px) 100vw, 735px\" \/><\/p>\n<p><strong>Option 2. <\/strong>To display the extraction progress, add the <strong>-v <\/strong>flag. The new command would be:<\/p>\n<pre>$ tar -xvf linuxhint.tar<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"738\" height=\"231\" class=\"wp-image-18151\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-7.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-7.png 738w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-7-300x94.png 300w\" sizes=\"auto, (max-width: 738px) 100vw, 738px\" \/><\/p>\n<p>Note that the extract options are the same despite the extension of the tar archive file.<\/p>\n<p><strong>Option 3. <\/strong>To list the contents of a tar file before extracting it, use the <strong>-t <\/strong>flag. For instance, to view the contents of our tar.gz file, the command would be:<\/p>\n<pre>$ tar -tf linux.tar.gz<\/pre>\n<p>You must add the <strong>-f <\/strong>to specify which tar file to extract.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"734\" height=\"207\" class=\"wp-image-18152\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-8.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-8.png 734w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-8-300x85.png 300w\" sizes=\"auto, (max-width: 734px) 100vw, 734px\" \/><\/p>\n<p><strong>Option 4. <\/strong>You can extract the contents of a tar file to a different location instead of the default, which is the current directory. For this, use the <strong>-C <\/strong>flag followed by the path.<\/p>\n<pre>$ tar -xf tar-file -C \/path\/directory<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"769\" height=\"156\" class=\"wp-image-18153\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-9.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-9.png 769w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-9-300x61.png 300w\" sizes=\"auto, (max-width: 769px) 100vw, 769px\" \/><\/p>\n<p><strong>Option 5. <\/strong>If you don\u2019t need to extract all the contents of the tar file, you can specify which specific files to extract by specifying their names separated by spaces. For instance, to extract two files, <strong>file1 <\/strong>and <strong>file2, <\/strong>the command would be:<\/p>\n<pre>$ tar -xfv linux.tar.gz file1 file2<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"742\" height=\"268\" class=\"wp-image-18154\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-10.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-10.png 742w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-10-300x108.png 300w\" sizes=\"auto, (max-width: 742px) 100vw, 742px\" \/><\/p>\n<p>In case of many files with the same extension and you want to extract them all, you can use the &#8212;<strong>wildcards <\/strong>followed by the extension. For instance, to extract the <strong>.txt <\/strong>files, the syntax would be.<\/p>\n<pre>$ tar -xf archive-file --wildcards \u2018*.txt\u2019<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"734\" height=\"157\" class=\"wp-image-18155\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-11.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-11.png 734w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-11-300x64.png 300w\" sizes=\"auto, (max-width: 734px) 100vw, 734px\" \/><\/p>\n<p>Similarly, as in the following image, you can extract specific folders from the tar file.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"741\" height=\"285\" class=\"wp-image-18156\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-12.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-12.png 741w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18112-12-300x115.png 300w\" sizes=\"auto, (max-width: 741px) 100vw, 741px\" \/><\/p>\n<p>We successfully unpacked the tar files using various options.<\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>Working with tar files shouldn\u2019t trouble you anymore. We covered the various options you have when you need to unpack the tar files. With this guide, you now understand how to handle the tar files easily.<\/p>","protected":false},"excerpt":{"rendered":"<p>Comprehensive tutorial on the various options to unpack the tar files in Linux and how to create it by following the step-by-step process and examples.<\/p>","protected":false},"author":104,"featured_media":18160,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1049],"tags":[],"class_list":["post-18112","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-commands"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/18112","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\/104"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=18112"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/18112\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/18160"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=18112"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=18112"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=18112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}