{"id":13283,"date":"2019-04-01T11:18:09","date_gmt":"2019-04-01T11:18:09","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=13283"},"modified":"2019-04-01T11:18:09","modified_gmt":"2019-04-01T11:18:09","slug":"how-to-download-and-extract-tar-files-with-one-command","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/01\/how-to-download-and-extract-tar-files-with-one-command\/","title":{"rendered":"How to Download and Extract Tar Files with One Command"},"content":{"rendered":"<p><strong>Tar<\/strong>\u00a0(<strong>Tape Archive<\/strong>) is a popular file archiving format in Linux. It can be used together with gzip (tar.gz) or bzip2 (tar.bz2) for compression. It is the most widely used command line utility to create compressed archive files (packages, source code, databases and so much more) that can be transferred easily from machine to another or over a network.<\/p>\n<p><strong>Read Also<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/18-tar-command-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">18 Tar Command Examples in Linux<\/a><\/p>\n<p>In this article, we will show you how to download tar archives using two well known\u00a0<a href=\"https:\/\/www.tecmint.com\/linux-command-line-tools-for-downloading-files\/\" target=\"_blank\" rel=\"noopener\">command line downloaders<\/a>\u2013\u00a0<a href=\"https:\/\/www.tecmint.com\/10-wget-command-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">wget<\/a>\u00a0or\u00a0<strong>cURL<\/strong>\u00a0and extract them with one single command.<\/p>\n<h3>How to Download and Extract File Using Wget Command<\/h3>\n<p>The example below shows how to download, unpack the latest\u00a0<strong>GeoLite2 Country<\/strong>\u00a0databases (use by the\u00a0<strong>GeoIP Nginx<\/strong>\u00a0module) in the current directory.<\/p>\n<pre># wget -c http:\/\/geolite.maxmind.com\/download\/geoip\/database\/GeoLite2-Country.tar.gz -O - | tar -xz\r\n<\/pre>\n<div id=\"attachment_28010\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/11\/Download-and-Extract-File-with-Wget.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-28010\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/11\/Download-and-Extract-File-with-Wget.png\" sizes=\"auto, (max-width: 802px) 100vw, 802px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/11\/Download-and-Extract-File-with-Wget.png 802w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/11\/Download-and-Extract-File-with-Wget-768x402.png 768w\" alt=\"Download and Extract File with Wget\" width=\"802\" height=\"420\" aria-describedby=\"caption-attachment-28010\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-28010\" class=\"wp-caption-text\">Download and Extract File with Wget<\/p>\n<\/div>\n<p>The wget option\u00a0<code>-O<\/code>\u00a0specifies a file to which the documents is written, and here we use\u00a0<code>-<\/code>, meaning it will written to standard output and piped to tar and the tar flag\u00a0<code>-x<\/code>\u00a0enables extraction of archive files and\u00a0<code>-z<\/code>decompresses, compressed archive files created by gzip.<\/p>\n<p>To extract\u00a0<a href=\"https:\/\/www.tecmint.com\/extract-tar-files-to-specific-or-different-directory-in-linux\/\" target=\"_blank\" rel=\"noopener\">tar files to specific directory<\/a>,\u00a0<strong>\/etc\/nginx\/<\/strong>\u00a0in this case, include use the\u00a0<code>-C<\/code>\u00a0flag as follows.<\/p>\n<p><strong>Note<\/strong>: If extracting files to particular directory that requires root permissions, use the\u00a0<a href=\"https:\/\/www.tecmint.com\/su-vs-sudo-and-how-to-configure-sudo-in-linux\/\" target=\"_blank\" rel=\"noopener\">sudo command<\/a>\u00a0to run tar.<\/p>\n<pre>$ sudo wget -c http:\/\/geolite.maxmind.com\/download\/geoip\/database\/GeoLite2-Country.tar.gz -O - | sudo tar -xz -C \/etc\/nginx\/\r\n<\/pre>\n<div id=\"attachment_28011\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/11\/Download-and-Extract-File-to-Directory.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-28011\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/11\/Download-and-Extract-File-to-Directory.png\" sizes=\"auto, (max-width: 802px) 100vw, 802px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/11\/Download-and-Extract-File-to-Directory.png 802w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/11\/Download-and-Extract-File-to-Directory-768x402.png 768w\" alt=\"Download and Extract File to Directory\" width=\"802\" height=\"420\" aria-describedby=\"caption-attachment-28011\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-28011\" class=\"wp-caption-text\">Download and Extract File to Directory<\/p>\n<\/div>\n<p>Alternatively, you can use the following command, here, the archive file will be downloaded on your system before you can extract it.<\/p>\n<pre>$ sudo wget -c http:\/\/geolite.maxmind.com\/download\/geoip\/database\/GeoLite2-Country.tar.gz &amp;&amp; tar -xzf  GeoLite2-Country.tar.gz\r\n<\/pre>\n<p>To extract compressed archive file to a specific directory, use the following command.<\/p>\n<pre>$ sudo wget -c http:\/\/geolite.maxmind.com\/download\/geoip\/database\/GeoLite2-Country.tar.gz &amp;&amp; sudo tar -xzf  GeoLite2-Country.tar.gz -C \/etc\/nginx\/\r\n<\/pre>\n<h3>How to Download and Extract File Using cURL Command<\/h3>\n<p>Considering the previous example, this is how you can use cURL to download and unpack archives in the current working directory.<\/p>\n<pre>$ sudo curl http:\/\/geolite.maxmind.com\/download\/geoip\/database\/GeoLite2-Country.tar.gz | tar -xz \r\n<\/pre>\n<div id=\"attachment_28012\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/11\/Download-and-Extract-File-with-cURL.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-28012\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/11\/Download-and-Extract-File-with-cURL.png\" sizes=\"auto, (max-width: 802px) 100vw, 802px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/11\/Download-and-Extract-File-with-cURL.png 802w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/11\/Download-and-Extract-File-with-cURL-768x202.png 768w\" alt=\"Download and Extract File with cURL\" width=\"802\" height=\"211\" aria-describedby=\"caption-attachment-28012\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-28012\" class=\"wp-caption-text\">Download and Extract File with cURL<\/p>\n<\/div>\n<p>To extract file to different directory while downloading, use the following command.<\/p>\n<pre>$ sudo curl http:\/\/geolite.maxmind.com\/download\/geoip\/database\/GeoLite2-Country.tar.gz | sudo tar -xz  -C \/etc\/nginx\/\r\nOR\r\n$ sudo curl http:\/\/geolite.maxmind.com\/download\/geoip\/database\/GeoLite2-Country.tar.gz &amp;&amp; sudo tar -xzf GeoLite2-Country.tar.gz -C \/etc\/nginx\/\r\n<\/pre>\n<p>That\u2019s all! In this short but useful guide, we showed you how to download and extract archive files in one single command. If you have any queries, use the comment section below to reach us.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/download-and-extract-tar-files-with-one-command\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Tar\u00a0(Tape Archive) is a popular file archiving format in Linux. It can be used together with gzip (tar.gz) or bzip2 (tar.bz2) for compression. It is the most widely used command line utility to create compressed archive files (packages, source code, databases and so much more) that can be transferred easily from machine to another or &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/01\/how-to-download-and-extract-tar-files-with-one-command\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Download and Extract Tar Files with One 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-13283","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\/13283","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=13283"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13283\/revisions"}],"predecessor-version":[{"id":13284,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13283\/revisions\/13284"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=13283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=13283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=13283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}