<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: How To: Compress a Directory of Files into Individual Archives</title>
	<atom:link href="http://r3dux.org/2009/04/how-to-compress-a-directory-of-files-into-individual-archives/feed/" rel="self" type="application/rss+xml" />
	<link>http://r3dux.org/2009/04/how-to-compress-a-directory-of-files-into-individual-archives/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-compress-a-directory-of-files-into-individual-archives</link>
	<description>A number-pimping side project from the valleys in *NEW* upside-down flavour.</description>
	<lastBuildDate>Fri, 10 Feb 2012 13:11:12 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
	<item>
		<title>By: Pawel</title>
		<link>http://r3dux.org/2009/04/how-to-compress-a-directory-of-files-into-individual-archives/#comment-7462</link>
		<dc:creator>Pawel</dc:creator>
		<pubDate>Tue, 07 Feb 2012 09:22:52 +0000</pubDate>
		<guid isPermaLink="false">http://r3dux.org/?p=439#comment-7462</guid>
		<description>Thanks a lot! This works like a charm. You knew it. :)
I am currently searching for more of you bash scripts. Since GUI is not very friendly for a screen reader under Linux I like to stay with the command line.
Best,
Pawel.</description>
		<content:encoded><![CDATA[<p>Thanks a lot! This works like a charm. You knew it. <img src='http://r3dux.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
I am currently searching for more of you bash scripts. Since GUI is not very friendly for a screen reader under Linux I like to stay with the command line.<br />
Best,<br />
Pawel.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: r3dux</title>
		<link>http://r3dux.org/2009/04/how-to-compress-a-directory-of-files-into-individual-archives/#comment-7459</link>
		<dc:creator>r3dux</dc:creator>
		<pubDate>Mon, 06 Feb 2012 03:00:37 +0000</pubDate>
		<guid isPermaLink="false">http://r3dux.org/?p=439#comment-7459</guid>
		<description>Just place the destination path before the &lt;strong&gt;&quot;$1&quot;.7z&lt;/strong&gt; part like this:

&lt;pre lang=&quot;bash&quot;&gt;find . -maxdepth 1 -type d -name &#039;*&#039; ! -name &#039;.&#039; -execdir sh -c &#039;7z a -mx9 -mmt &lt;destination-path&gt;/&quot;$1&quot;.7z &quot;$1&quot;&#039; : {} \;&lt;/pre&gt;

For example, if I wanted to compress each directory into a 7z archive and have them placed in the folder &lt;strong&gt;~/backups&lt;/strong&gt; (where ~ gets substituted for the current users home directory, so for me would equate to &lt;strong&gt;/home/r3dux&lt;/strong&gt;), I could use:

&lt;pre lang=&quot;bash&quot;&gt;find . -maxdepth 1 -type d -name &#039;*&#039; ! -name &#039;.&#039; -execdir sh -c &#039;7z a -mx9 -mmt ~/backups/&quot;$1&quot;.7z &quot;$1&quot;&#039; : {} \;&lt;/pre&gt;

Hope this helps.</description>
		<content:encoded><![CDATA[<p>Just place the destination path before the <strong>&#8220;$1&#8243;.7z</strong> part like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-maxdepth</span> <span style="color: #000000;">1</span> <span style="color: #660033;">-type</span> d <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*'</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'.'</span> <span style="color: #660033;">-execdir</span> <span style="color: #c20cb9; font-weight: bold;">sh</span> <span style="color: #660033;">-c</span> <span style="color: #ff0000;">'7z a -mx9 -mmt &lt;destination-path&gt;/&quot;$1&quot;.7z &quot;$1&quot;'</span> : <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \;</pre></div></div>

<p>For example, if I wanted to compress each directory into a 7z archive and have them placed in the folder <strong>~/backups</strong> (where ~ gets substituted for the current users home directory, so for me would equate to <strong>/home/r3dux</strong>), I could use:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-maxdepth</span> <span style="color: #000000;">1</span> <span style="color: #660033;">-type</span> d <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*'</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'.'</span> <span style="color: #660033;">-execdir</span> <span style="color: #c20cb9; font-weight: bold;">sh</span> <span style="color: #660033;">-c</span> <span style="color: #ff0000;">'7z a -mx9 -mmt ~/backups/&quot;$1&quot;.7z &quot;$1&quot;'</span> : <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \;</pre></div></div>

<p>Hope this helps.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pawel</title>
		<link>http://r3dux.org/2009/04/how-to-compress-a-directory-of-files-into-individual-archives/#comment-7458</link>
		<dc:creator>Pawel</dc:creator>
		<pubDate>Mon, 06 Feb 2012 00:22:21 +0000</pubDate>
		<guid isPermaLink="false">http://r3dux.org/?p=439#comment-7458</guid>
		<description>Thanks for sharing this with us. I am almost there. Only thing which is missing is relocating 7z files to another location. adding -o&quot;/newpath/$1&quot;.7z and other combination did not work for me. Any suggestion please? I have over 630 GBs collection in front of me to be compressed and archived, so you assistance is highly appreciated.
Best,
Pawel.</description>
		<content:encoded><![CDATA[<p>Thanks for sharing this with us. I am almost there. Only thing which is missing is relocating 7z files to another location. adding -o&#8221;/newpath/$1&#8243;.7z and other combination did not work for me. Any suggestion please? I have over 630 GBs collection in front of me to be compressed and archived, so you assistance is highly appreciated.<br />
Best,<br />
Pawel.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: r3dux</title>
		<link>http://r3dux.org/2009/04/how-to-compress-a-directory-of-files-into-individual-archives/#comment-7457</link>
		<dc:creator>r3dux</dc:creator>
		<pubDate>Sun, 05 Feb 2012 22:29:57 +0000</pubDate>
		<guid isPermaLink="false">http://r3dux.org/?p=439#comment-7457</guid>
		<description>I tried it with the -d instead of -f and got the &lt;strong&gt;..7z&lt;/strong&gt; file as well (which is a single archive of everything in all the directories). But I also noticed that the command went into every folder and compressed every subfolder into its own .7z file, too! Not what we want!

The fix for this is to tell find to only traverse 1 directory deep (&lt;strong&gt;-maxdepth 1&lt;/strong&gt; - keep this as the first parameter specifed or find will complain), and then also tell it to exclude the current directory we&#039;re running the command in (&lt;strong&gt;! -name &#039;.&#039;&lt;/strong&gt;).

The end result to compress all subdirectories in the directory where you run the command then becomes:

&lt;pre lang=&quot;bash&quot;&gt;find . -maxdepth 1 -type d -name &#039;*&#039; ! -name &#039;*.7z&#039; ! -name &#039;.&#039; -execdir sh -c &#039;7z a -mx9 -mmt &quot;$1&quot;.7z &quot;$1&quot;&#039; : {} \;&lt;/pre&gt;

But this will also exclude any directories that end with .7z, which you&#039;re unlikely to have, so a better version is:

&lt;pre lang=&quot;bash&quot;&gt;find . -maxdepth 1 -type d -name &#039;*&#039; ! -name &#039;.&#039; -execdir sh -c &#039;7z a -mx9 -mmt &quot;$1&quot;.7z &quot;$1&quot;&#039; : {} \;&lt;/pre&gt;

Cheers!</description>
		<content:encoded><![CDATA[<p>I tried it with the -d instead of -f and got the <strong>..7z</strong> file as well (which is a single archive of everything in all the directories). But I also noticed that the command went into every folder and compressed every subfolder into its own .7z file, too! Not what we want!</p>
<p>The fix for this is to tell find to only traverse 1 directory deep (<strong>-maxdepth 1</strong> &#8211; keep this as the first parameter specifed or find will complain), and then also tell it to exclude the current directory we&#8217;re running the command in (<strong>! -name &#8216;.&#8217;</strong>).</p>
<p>The end result to compress all subdirectories in the directory where you run the command then becomes:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-maxdepth</span> <span style="color: #000000;">1</span> <span style="color: #660033;">-type</span> d <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*'</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.7z'</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'.'</span> <span style="color: #660033;">-execdir</span> <span style="color: #c20cb9; font-weight: bold;">sh</span> <span style="color: #660033;">-c</span> <span style="color: #ff0000;">'7z a -mx9 -mmt &quot;$1&quot;.7z &quot;$1&quot;'</span> : <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \;</pre></div></div>

<p>But this will also exclude any directories that end with .7z, which you&#8217;re unlikely to have, so a better version is:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-maxdepth</span> <span style="color: #000000;">1</span> <span style="color: #660033;">-type</span> d <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*'</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'.'</span> <span style="color: #660033;">-execdir</span> <span style="color: #c20cb9; font-weight: bold;">sh</span> <span style="color: #660033;">-c</span> <span style="color: #ff0000;">'7z a -mx9 -mmt &quot;$1&quot;.7z &quot;$1&quot;'</span> : <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \;</pre></div></div>

<p>Cheers!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pawel</title>
		<link>http://r3dux.org/2009/04/how-to-compress-a-directory-of-files-into-individual-archives/#comment-7453</link>
		<dc:creator>Pawel</dc:creator>
		<pubDate>Sun, 05 Feb 2012 18:38:41 +0000</pubDate>
		<guid isPermaLink="false">http://r3dux.org/?p=439#comment-7453</guid>
		<description>Hi,
To compress multiple directories into separate archive files I modified your one liner by changing -type f to -type d and everything seemed to be fine except I was gettin a strange, huge ./.7z file besides all of the required archive files. Not sure what needs to be modified to make it work &#039;better&#039;.
Thanks,
Pawel.</description>
		<content:encoded><![CDATA[<p>Hi,<br />
To compress multiple directories into separate archive files I modified your one liner by changing -type f to -type d and everything seemed to be fine except I was gettin a strange, huge ./.7z file besides all of the required archive files. Not sure what needs to be modified to make it work &#8216;better&#8217;.<br />
Thanks,<br />
Pawel.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: r3dux</title>
		<link>http://r3dux.org/2009/04/how-to-compress-a-directory-of-files-into-individual-archives/#comment-5816</link>
		<dc:creator>r3dux</dc:creator>
		<pubDate>Thu, 13 May 2010 06:52:16 +0000</pubDate>
		<guid isPermaLink="false">http://r3dux.org/?p=439#comment-5816</guid>
		<description>Got a hit from a forum which saw the post, who also say that using &quot;~n&quot; will strip the file extension, for example:

&lt;pre&gt;for %f in (*.adf) do echo %~nf&lt;/pre&gt;

Just saving this info here for future reference! :)</description>
		<content:encoded><![CDATA[<p>Got a hit from a forum which saw the post, who also say that using &#8220;~n&#8221; will strip the file extension, for example:</p>
<pre>for %f in (*.adf) do echo %~nf</pre>
<p>Just saving this info here for future reference! <img src='http://r3dux.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James McDonald</title>
		<link>http://r3dux.org/2009/04/how-to-compress-a-directory-of-files-into-individual-archives/#comment-5804</link>
		<dc:creator>James McDonald</dc:creator>
		<pubDate>Mon, 10 May 2010 11:13:22 +0000</pubDate>
		<guid isPermaLink="false">http://r3dux.org/?p=439#comment-5804</guid>
		<description>A belated &quot;You&#039;re Welcome!&quot; :)</description>
		<content:encoded><![CDATA[<p>A belated &#8220;You&#8217;re Welcome!&#8221; <img src='http://r3dux.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: r3dux</title>
		<link>http://r3dux.org/2009/04/how-to-compress-a-directory-of-files-into-individual-archives/#comment-3999</link>
		<dc:creator>r3dux</dc:creator>
		<pubDate>Thu, 03 Dec 2009 21:56:29 +0000</pubDate>
		<guid isPermaLink="false">http://r3dux.org/?p=439#comment-3999</guid>
		<description>Spunky,

Finally got some free time to have a look at your question - the following line will do the job, and will deal with spaces in filenames just fine:

&lt;pre lang=&quot;bash&quot;&gt;find . -type f -name &#039;*&#039; ! -name &#039;*.7z&#039; -execdir sh -c &#039;7z a -mx9 -mmt &quot;$1&quot;.7z &quot;$1&quot;&#039; : {} \;&lt;/pre&gt;

The above will compress all files (except ones ending in .7z) in all directories to their own unique archives in whatever directory they&#039;re currently in, so &quot;./some documents/some doc.txt&quot; will become &quot;/some document/some doc.txt.7z&quot; - which is what I think you were after...

All the best,
r3dux</description>
		<content:encoded><![CDATA[<p>Spunky,</p>
<p>Finally got some free time to have a look at your question &#8211; the following line will do the job, and will deal with spaces in filenames just fine:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-type</span> f <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*'</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.7z'</span> <span style="color: #660033;">-execdir</span> <span style="color: #c20cb9; font-weight: bold;">sh</span> <span style="color: #660033;">-c</span> <span style="color: #ff0000;">'7z a -mx9 -mmt &quot;$1&quot;.7z &quot;$1&quot;'</span> : <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \;</pre></div></div>

<p>The above will compress all files (except ones ending in .7z) in all directories to their own unique archives in whatever directory they&#8217;re currently in, so &#8220;./some documents/some doc.txt&#8221; will become &#8220;/some document/some doc.txt.7z&#8221; &#8211; which is what I think you were after&#8230;</p>
<p>All the best,<br />
r3dux</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Spunky</title>
		<link>http://r3dux.org/2009/04/how-to-compress-a-directory-of-files-into-individual-archives/#comment-3766</link>
		<dc:creator>Spunky</dc:creator>
		<pubDate>Fri, 13 Nov 2009 13:30:05 +0000</pubDate>
		<guid isPermaLink="false">http://r3dux.org/?p=439#comment-3766</guid>
		<description>Hi,

Sorry for resurrecting an old topic, but I&#039;ve been trying to modify the one liner to compress all files in all directories, including subdirectories, using 7zip but I can&#039;t get it to work.

I&#039;m a total novice and don&#039;t really understand how any of this works. Here&#039;s my failed stab at modifying the one liner:

find . -type f -name &#039;*.*&#039; -execdir sh -c &#039;7z a -mx9 -mmt -tbzip2 %1.bz2 %1&#039; : {} \;

Would anyone be able to help?

Thanks.</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>Sorry for resurrecting an old topic, but I&#8217;ve been trying to modify the one liner to compress all files in all directories, including subdirectories, using 7zip but I can&#8217;t get it to work.</p>
<p>I&#8217;m a total novice and don&#8217;t really understand how any of this works. Here&#8217;s my failed stab at modifying the one liner:</p>
<p>find . -type f -name &#8216;*.*&#8217; -execdir sh -c &#8217;7z a -mx9 -mmt -tbzip2 %1.bz2 %1&#8242; : {} \;</p>
<p>Would anyone be able to help?</p>
<p>Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: r3dux</title>
		<link>http://r3dux.org/2009/04/how-to-compress-a-directory-of-files-into-individual-archives/#comment-355</link>
		<dc:creator>r3dux</dc:creator>
		<pubDate>Mon, 27 Apr 2009 01:12:37 +0000</pubDate>
		<guid isPermaLink="false">http://r3dux.org/?p=439#comment-355</guid>
		<description>MedicalFlyer,

As a quick &amp; dirty batch file method, you could use this:

&lt;pre lang=&quot;bash&quot;&gt;
@ECHO OFF
FOR /F %%f IN (&#039;dir /b .\*.%1&#039;) DO echo Compress %%f to %%f.zip or something here...
&lt;/pre&gt;

Copy &amp; paste the above two lines of code into a new batch file, maybe &quot;compress.bat&quot;, then run it and pass it an extension like &quot;compress doc&quot; to compress all files in the current directory with the extension .doc.

After the DO part, you&#039;d want to put something like &quot;pkzip a %%f %%f.zip&quot; or the like instead of the simple echo I&#039;ve put above.

Cheers!</description>
		<content:encoded><![CDATA[<p>MedicalFlyer,</p>
<p>As a quick &#038; dirty batch file method, you could use this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">@</span>ECHO OFF
FOR <span style="color: #000000; font-weight: bold;">/</span>F <span style="color: #000000; font-weight: bold;">%%</span>f IN <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">'dir /b .\*.%1'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> DO <span style="color: #7a0874; font-weight: bold;">echo</span> Compress <span style="color: #000000; font-weight: bold;">%%</span>f to <span style="color: #000000; font-weight: bold;">%%</span>f.zip or something here...</pre></div></div>

<p>Copy &#038; paste the above two lines of code into a new batch file, maybe &#8220;compress.bat&#8221;, then run it and pass it an extension like &#8220;compress doc&#8221; to compress all files in the current directory with the extension .doc.</p>
<p>After the DO part, you&#8217;d want to put something like &#8220;pkzip a %%f %%f.zip&#8221; or the like instead of the simple echo I&#8217;ve put above.</p>
<p>Cheers!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

