{"id":897,"date":"2011-09-10T01:20:22","date_gmt":"2011-09-10T05:20:22","guid":{"rendered":"http:\/\/nylinuxhelp.com\/blogs\/?p=897"},"modified":"2011-09-10T01:20:22","modified_gmt":"2011-09-10T05:20:22","slug":"untar-several-files-to-a-directory","status":"publish","type":"post","link":"https:\/\/nylinuxhelp.com\/blogs\/command-line\/untar-several-files-to-a-directory","title":{"rendered":"Untar Several Files to a directory"},"content":{"rendered":"<h2>Today we&#8217;re going to talk about the UNIX tar command.<\/h2>\n<h4>Specifically, how to use tar to extract or unpack several archives (tar.gz files). \u00a0Only &#8211; instead of extracting them to the same directory, we&#8217;re going to extract them to a named directory.<\/h4>\n<p>This utility came in handy after downloading close to 10 gkrellm themes from <a title=\"Gkrellm Themes for Download\" href=\"http:\/\/www.muhri.net\/gkrellm\/nav.php3?node=gkrellmall&amp;sort=added&amp;conf=DESC\">http:\/\/www.muhri.net<\/a>\u00a0. I have used\u00a0the Gkrellm Monitoring tool over the years and was always disappointed with the (somewhat) `boring` stock themes. \u00a0I mean, if you&#8217;re going to have something sitting on your desktop, using resources to report on resources, then why not have it look slick, sick, or at the very least\u2014&#8221;easy on the eyes&#8221;&#8230; right?<\/p>\n<h4>Why would anyone want to unpack tar.gz files with the command line in Linux when there are GUI tools available?<\/h4>\n<p>Right, the linux OS comes packed with tons of GUIs to handle files and archives. \u00a0We have programs such as FileRoller. \u00a0I have used it but imagine you have downloaded (oh I don&#8217;t know, twelve) archives that are themes for gkrellm. \u00a0Would you really want to use the manual effort of unpacking all of them first, directing the GUI (with more clicks) where to save the extracted files to?<\/p>\n<p>What if I told you that you can accomplish the same in the Linux Shell with a basic loop over a set of tar.gz files? \u00a0You&#8217;d probably want to take the quick way I bet. \u00a0I know I did.<\/p>\n<p>Ok, get on to it already. \u00a0Right. Here we go. \u00a0Firstly, I&#8217;d be a bad dude if I didn&#8217;t at least name some links that I googled along the way to building the handy-dandy loop I&#8217;m about to share with ye. \u00a0<a title=\"Untar to a specific directory using Linux\" href=\"http:\/\/lejalgenes.com\/techtips\/tips\/Linux\/Untar_to_a_specific_directory_and_other_tar_tricks.php\">http:\/\/lejalgenes.com\/<\/a>\u00a0very simple layout, 2 commands that do the trick. \u00a0And\u00a0<a title=\"Linux Questions Untar\" href=\"http:\/\/www.linuxquestions.org\/questions\/linux-general-1\/untar-to-a-specific-folder-507383\/\">http:\/\/www.linuxquestions.org\/<\/a>\u00a0which has the command, and provides advice too.<\/p>\n<p>Using the basic concept of the command, which unpacks a tar.gz to a named directory:<\/p>\n<pre>tar -zxvf tarball.tar.gz -C &lt;directory&gt;<\/pre>\n<p>Then, using a loop construct, where the find command provides a list of tar.gz files, we iterate over the list, unpacking each one to the specified directory following the -C.<\/p>\n<p>The setup:<\/p>\n<ol>\n<li>Have all of your (downloaded) tar.gz files in the same directory. \u00a0You may want to get rid of archives that are unrelated to gkrellm themes.<\/li>\n<li>CD to that directory. \u00a0We will extract to the .gkrellm2\/themes.<\/li>\n<\/ol>\n<pre>for fyl in $(find . -type f -name \"*gz\");\\<\/pre>\n<pre>do tar -zxvf $fyl -C \/home\/awsmeadam\/.gkrellm2\/themes; done<\/pre>\n<p>And that&#8217;s it. \u00a0Done. \u00a0Did you download more tar.gz themes? \u00a0Ok, run the command again.<\/p>\n<h4>If I run the command again, the previously-unpacked files will get over-written, won&#8217;t they?<\/h4>\n<p>Yes, they will. \u00a0In most cases, this is bad. \u00a0But since this is a theme unpack, you really have little to worry about unless you&#8217;ve edited or otherwise customized a theme.<\/p>\n<p>Enjoy, and happy Linux-ing.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today we&#8217;re going to talk about the UNIX tar command. Specifically, how to use tar to extract or unpack several archives (tar.gz files). \u00a0Only &#8211; instead of extracting them to the same directory, we&#8217;re going to extract them to a named directory. This utility came in handy after downloading close to 10 gkrellm themes from [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,12,23],"tags":[],"class_list":["post-897","post","type-post","status-publish","format-standard","hentry","category-command-line","category-learn-linux","category-use-linux"],"_links":{"self":[{"href":"https:\/\/nylinuxhelp.com\/blogs\/wp-json\/wp\/v2\/posts\/897","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nylinuxhelp.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nylinuxhelp.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nylinuxhelp.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nylinuxhelp.com\/blogs\/wp-json\/wp\/v2\/comments?post=897"}],"version-history":[{"count":19,"href":"https:\/\/nylinuxhelp.com\/blogs\/wp-json\/wp\/v2\/posts\/897\/revisions"}],"predecessor-version":[{"id":916,"href":"https:\/\/nylinuxhelp.com\/blogs\/wp-json\/wp\/v2\/posts\/897\/revisions\/916"}],"wp:attachment":[{"href":"https:\/\/nylinuxhelp.com\/blogs\/wp-json\/wp\/v2\/media?parent=897"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nylinuxhelp.com\/blogs\/wp-json\/wp\/v2\/categories?post=897"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nylinuxhelp.com\/blogs\/wp-json\/wp\/v2\/tags?post=897"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}