<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Chris JeanChris Jean &#187; zip</title>
	<atom:link href="http://chrisjean.com/tag/zip/feed/" rel="self" type="application/rss+xml" />
	<link>http://chrisjean.com</link>
	<description>Linux, WordPress, programming, anime, and other stuff</description>
	<lastBuildDate>Mon, 16 Jan 2012 15:22:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Unzip Multiple Files from Linux Command Line</title>
		<link>http://chrisjean.com/2009/02/26/unzip-multiple-files-from-linux-command-line/</link>
		<comments>http://chrisjean.com/2009/02/26/unzip-multiple-files-from-linux-command-line/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 06:00:45 +0000</pubDate>
		<dc:creator>Chris Jean</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tips 'n Tricks]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[Mastering The Command Line]]></category>
		<category><![CDATA[unzip]]></category>
		<category><![CDATA[zip]]></category>

		<guid isPermaLink="false">http://gaarai.com/?p=1196</guid>
		<description><![CDATA[Here&#8217;s a quick tip that will help you work with multiple zip files on the command line. If you are in a folder and have three zip files in it (a.zip, b.zip, c.zip) that you want to unzip, &#8220;no problem,&#8221; you think, &#8220;I can take care of that with one command.&#8221; So, you quickly run [...]]]></description>
			<content:encoded><![CDATA[<!-- filtered -->
<p>Here&#8217;s a quick tip that will help you work with multiple zip files on the command line.</p>
<p>If you are in a folder and have three zip files in it (a.zip, b.zip, c.zip) that you want to unzip, &#8220;no problem,&#8221; you think, &#8220;I can take care of that with one command.&#8221; So, you quickly run the following:</p>
<div class="code">unzip *.zip</div>
<p>However, rather than having the unzip program nicely unzip each file one after another, you receive the following:</p>
<div class="code">Archive:  a.zip<br />
caution: filename not matched:  b.zip<br />
caution: filename not matched:  c.zip</div>
<p>I&#8217;m sure that this is not what you were expecting. I know I certainly wasn&#8217;t expecting this when I first tried it. However, this problem can help us understand more of how the command line works.<br />
<span id="more-1196"></span></p>
<h3>The Problem</h3>
<p>Whenever you use a wildcard (*), the shell itself will expand that and pass the results to the program rather than the program handling the expansion itself. That means that our previous command was actually expanded to the following before being executed:</p>
<div class="code">unzip a.zip b.zip c.zip</div>
<p>Again, this may not look odd since other programs (such as mkdir, chmod, etc) can take one or more arguments and repeat the process for each. However, unzip is different and actually has use for the additional arguments. If you specify additional arguments after the zip file name, unzip will try to only extract those specific files from the archive rather than all the files.</p>
<p>The previous command told unzip that it should extract b.zip and c.zip from inside the a.zip archive. Since those files don&#8217;t exist inside a.zip, we get the nasty output seen earlier.</p>
<p>You might think that you will have to manually unzip each archive one at a time, but you&#8217;d be wrong.</p>
<h3>The Solution</h3>
<p>Just because the shell expands out wildcard characters automatically doesn&#8217;t mean that programs can&#8217;t as well. The simple solution to this problem is to quote the argument to prevent the shell from interpreting it:</p>
<div class="code">unzip &#8216;*.zip&#8217;</div>
<p>That&#8217;s all there is to it. I&#8217;ve seen solutions from coding loops in bash script to running find combined with xargs, but none of that is necessary. Simply let unzip itself take care of things for you.</p>
]]></content:encoded>
			<wfw:commentRss>http://chrisjean.com/2009/02/26/unzip-multiple-files-from-linux-command-line/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

