<?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: Linux: xargs vs. exec {}</title>
	<atom:link href="http://danielmiessler.com/blog/linux-xargs-vs-exec/feed" rel="self" type="application/rss+xml" />
	<link>http://danielmiessler.com/blog/linux-xargs-vs-exec</link>
	<description>grep understanding</description>
	<lastBuildDate>Thu, 18 Mar 2010 04:37:26 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: dchen</title>
		<link>http://danielmiessler.com/blog/linux-xargs-vs-exec/comment-page-1#comment-243409</link>
		<dc:creator>dchen</dc:creator>
		<pubDate>Thu, 08 Oct 2009 02:14:14 +0000</pubDate>
		<guid isPermaLink="false">http://dmiessler.com/archives/986#comment-243409</guid>
		<description>&lt;p&gt;You can have the same behavior with find by replacing the ; with a +. To illustrate, try running the following:&lt;br&gt;&lt;br&gt;find . -exec echo {} ;&lt;br&gt;find . -exec echo {} +&lt;br&gt;find . -print0 &#124; xargs -0 echo&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>You can have the same behavior with find by replacing the ; with a +. To illustrate, try running the following:<br /><br />find . -exec echo {} ;<br />find . -exec echo {} +<br />find . -print0 | xargs -0 echo</p>]]></content:encoded>
	</item>
	<item>
		<title>By: dj</title>
		<link>http://danielmiessler.com/blog/linux-xargs-vs-exec/comment-page-1#comment-241912</link>
		<dc:creator>dj</dc:creator>
		<pubDate>Thu, 07 May 2009 02:45:05 +0000</pubDate>
		<guid isPermaLink="false">http://dmiessler.com/archives/986#comment-241912</guid>
		<description>&lt;p&gt;Doing some reading on find, xargs and exec.   I don&#039;t know when it was added, but on the -exec, change the &quot;;&quot; to &quot;+&quot; to &quot;aggregated into sets&quot;.  The test results will change a lot.&lt;br&gt;See: &lt;a href=&quot;http://www.opengroup.org/onlinepubs/009695399/utilities/find.html&quot; rel=&quot;nofollow&quot;&gt;http://www.opengroup.org/onlinepubs/009695399/u...&lt;/a&gt;&lt;br&gt;&lt;br&gt;&gt;&quot;variable is still delimited at the first space&quot;&lt;br&gt;Check out the documentation at: &lt;a href=&quot;http://www.tldp.org&quot; rel=&quot;nofollow&quot;&gt;www.tldp.org&lt;/a&gt; (Short for: The Linux Documentation Project) on bash, quotes, and file name expansion.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Doing some reading on find, xargs and exec.   I don&#39;t know when it was added, but on the -exec, change the &#8220;;&#8221; to &#8220;+&#8221; to &#8220;aggregated into sets&#8221;.  The test results will change a lot.<br />See: <a href="http://www.opengroup.org/onlinepubs/009695399/utilities/find.html" rel="nofollow"></a><a href="http://www.opengroup.org/onlinepubs/009695399/u.." rel="nofollow">http://www.opengroup.org/onlinepubs/009695399/u..</a>.<br /><br />&gt;&#8221;variable is still delimited at the first space&#8221;<br />Check out the documentation at: <a href="http://www.tldp.org" rel="nofollow">http://www.tldp.org</a> (Short for: The Linux Documentation Project) on bash, quotes, and file name expansion.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: dj</title>
		<link>http://danielmiessler.com/blog/linux-xargs-vs-exec/comment-page-1#comment-241622</link>
		<dc:creator>dj</dc:creator>
		<pubDate>Wed, 06 May 2009 22:45:05 +0000</pubDate>
		<guid isPermaLink="false">http://dmiessler.com/archives/986#comment-241622</guid>
		<description>&lt;p&gt;Doing some reading on find, xargs and exec.   I don&#039;t know when it was added, but on the -exec, change the &quot;;&quot; to &quot;+&quot; to &quot;aggregated into sets&quot;.  The test results will change a lot.&lt;br&gt;See: &lt;a href=&quot;http://www.opengroup.org/onlinepubs/009695399/utilities/find.html&quot; rel=&quot;nofollow&quot;&gt;http://www.opengroup.org/onlinepubs/009695399/u...&lt;/a&gt;&lt;br&gt;&lt;br&gt;&gt;&quot;variable is still delimited at the first space&quot;&lt;br&gt;Check out the documentation at: &lt;a href=&quot;http://www.tldp.org&quot; rel=&quot;nofollow&quot;&gt;www.tldp.org&lt;/a&gt; (Short for: The Linux Documentation Project) on bash, quotes, and file name expansion.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Doing some reading on find, xargs and exec.   I don&#39;t know when it was added, but on the -exec, change the &#8220;;&#8221; to &#8220;+&#8221; to &#8220;aggregated into sets&#8221;.  The test results will change a lot.<br />See: <a href="http://www.opengroup.org/onlinepubs/009695399/utilities/find.html" rel="nofollow"></a><a href="http://www.opengroup.org/onlinepubs/009695399/u.." rel="nofollow">http://www.opengroup.org/onlinepubs/009695399/u..</a>.<br /><br />&gt;&#8221;variable is still delimited at the first space&#8221;<br />Check out the documentation at: <a href="http://www.tldp.org" rel="nofollow">http://www.tldp.org</a> (Short for: The Linux Documentation Project) on bash, quotes, and file name expansion.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: neuralstatic</title>
		<link>http://danielmiessler.com/blog/linux-xargs-vs-exec/comment-page-1#comment-240750</link>
		<dc:creator>neuralstatic</dc:creator>
		<pubDate>Wed, 25 Feb 2009 18:03:14 +0000</pubDate>
		<guid isPermaLink="false">http://dmiessler.com/archives/986#comment-240750</guid>
		<description>&lt;p&gt;that does not match my experience, justin.&lt;br&gt;even if it did echo it as a complete name (which it doesn&#039;t for me), then acting on that variable is still delimited at the first space, right?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>that does not match my experience, justin.<br />even if it did echo it as a complete name (which it doesn&#39;t for me), then acting on that variable is still delimited at the first space, right?</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Justin McBroom</title>
		<link>http://danielmiessler.com/blog/linux-xargs-vs-exec/comment-page-1#comment-9195</link>
		<dc:creator>Justin McBroom</dc:creator>
		<pubDate>Wed, 01 Nov 2006 22:08:48 +0000</pubDate>
		<guid isPermaLink="false">http://dmiessler.com/archives/986#comment-9195</guid>
		<description>&lt;p&gt;tomchuck,&lt;/p&gt;

&lt;p&gt;bash has no problem looping through a list of files with our without spaces, you just
have to make sure and put quotes around the loop variable:&lt;/p&gt;

&lt;p&gt;for png in *.png ; do echo pngcrush &quot;$png&quot;; done&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>tomchuck,</p>

<p>bash has no problem looping through a list of files with our without spaces, you just
have to make sure and put quotes around the loop variable:</p>

<p>for png in *.png ; do echo pngcrush &#8220;$png&#8221;; done</p>]]></content:encoded>
	</item>
	<item>
		<title>By: foof</title>
		<link>http://danielmiessler.com/blog/linux-xargs-vs-exec/comment-page-1#comment-9168</link>
		<dc:creator>foof</dc:creator>
		<pubDate>Wed, 01 Nov 2006 06:45:48 +0000</pubDate>
		<guid isPermaLink="false">http://dmiessler.com/archives/986#comment-9168</guid>
		<description>&lt;p&gt;When using the -i or -I string replacement for xargs (needed for any
complex operation such as the convert example above), then it
becomes impossible for xargs to group the arguments together and
it has to execute them one at a time as in -exec.  If you change the
example above to:&lt;/p&gt;

&lt;h1&gt;time find . -name “*.jpg” -print0 &#124; xargs -0 -ifile ls file&lt;/h1&gt;

&lt;p&gt;you&#039;ll see it has almost exactly the same running time as -exec.&lt;/p&gt;

&lt;p&gt;This dual behavior of xargs can be surprising - a complex command
written with -i may work fine since it only receives one argument at
a time, but break suddenly if the -i is removed and the command
faces batched arguments.  It&#039;s probably best to use the -exec
option to find(1) wherever you would need to use -i in xargs to avoid
this confusion.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>When using the -i or -I string replacement for xargs (needed for any
complex operation such as the convert example above), then it
becomes impossible for xargs to group the arguments together and
it has to execute them one at a time as in -exec.  If you change the
example above to:</p>

<h1>time find . -name “*.jpg” -print0 | xargs -0 -ifile ls file</h1>

<p>you&#8217;ll see it has almost exactly the same running time as -exec.</p>

<p>This dual behavior of xargs can be surprising &#8211; a complex command
written with -i may work fine since it only receives one argument at
a time, but break suddenly if the -i is removed and the command
faces batched arguments.  It&#8217;s probably best to use the -exec
option to find(1) wherever you would need to use -i in xargs to avoid
this confusion.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: tomchuk</title>
		<link>http://danielmiessler.com/blog/linux-xargs-vs-exec/comment-page-1#comment-9120</link>
		<dc:creator>tomchuk</dc:creator>
		<pubDate>Tue, 31 Oct 2006 04:27:33 +0000</pubDate>
		<guid isPermaLink="false">http://dmiessler.com/archives/986#comment-9120</guid>
		<description>&lt;p&gt;Mike,&lt;/p&gt;

&lt;p&gt;bash loops work great until you hit a filename with a space.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Mike,</p>

<p>bash loops work great until you hit a filename with a space.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Miessler</title>
		<link>http://danielmiessler.com/blog/linux-xargs-vs-exec/comment-page-1#comment-9119</link>
		<dc:creator>Daniel Miessler</dc:creator>
		<pubDate>Tue, 31 Oct 2006 04:26:07 +0000</pubDate>
		<guid isPermaLink="false">http://dmiessler.com/archives/986#comment-9119</guid>
		<description>&lt;p&gt;To those who mentioned caching, I performed the test at least ten times using both commands to produce the numbers I did. I ran into the caching issue as well on other systems, but on the system in question I think I was getting real numbers. Again, both numbers come from the command being run multiple times. I didn&#039;t run one without the cache and one with it.&lt;/p&gt;

&lt;p&gt;That, I agree, would have been lame...&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>To those who mentioned caching, I performed the test at least ten times using both commands to produce the numbers I did. I ran into the caching issue as well on other systems, but on the system in question I think I was getting real numbers. Again, both numbers come from the command being run multiple times. I didn&#8217;t run one without the cache and one with it.</p>

<p>That, I agree, would have been lame&#8230;</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://danielmiessler.com/blog/linux-xargs-vs-exec/comment-page-1#comment-9116</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Tue, 31 Oct 2006 02:04:52 +0000</pubDate>
		<guid isPermaLink="false">http://dmiessler.com/archives/986#comment-9116</guid>
		<description>&lt;p&gt;mikkom,&lt;/p&gt;

&lt;p&gt;If you&#039;re using &#039;bash&#039; as your shell (you should be), it&#039;s often easier to just say &#039;for i in *.jpg; do convert file blah...&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>mikkom,</p>

<p>If you&#8217;re using &#8216;bash&#8217; as your shell (you should be), it&#8217;s often easier to just say &#8216;for i in *.jpg; do convert file blah&#8230;</p>]]></content:encoded>
	</item>
	<item>
		<title>By: admp</title>
		<link>http://danielmiessler.com/blog/linux-xargs-vs-exec/comment-page-1#comment-9106</link>
		<dc:creator>admp</dc:creator>
		<pubDate>Mon, 30 Oct 2006 21:54:23 +0000</pubDate>
		<guid isPermaLink="false">http://dmiessler.com/archives/986#comment-9106</guid>
		<description>&lt;p&gt;TD: it&#039;s filesystem kernel-level cache. This is simply incorrect method of benchmarking. May the author check inner details better next time. Kudos.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>TD: it&#8217;s filesystem kernel-level cache. This is simply incorrect method of benchmarking. May the author check inner details better next time. Kudos.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: TD</title>
		<link>http://danielmiessler.com/blog/linux-xargs-vs-exec/comment-page-1#comment-9103</link>
		<dc:creator>TD</dc:creator>
		<pubDate>Mon, 30 Oct 2006 20:00:55 +0000</pubDate>
		<guid isPermaLink="false">http://dmiessler.com/archives/986#comment-9103</guid>
		<description>&lt;p&gt;If you try the commands in the other order, i.e. xargs first then -exec the exec is faster, at least in my little test of finding all jpgs in my home dir. xargs took 2mins exec took 21 secs.&lt;/p&gt;

&lt;p&gt;/me wonders if find caches results or something to speed it up when you do a similar find afterwards.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>If you try the commands in the other order, i.e. xargs first then -exec the exec is faster, at least in my little test of finding all jpgs in my home dir. xargs took 2mins exec took 21 secs.</p>

<p>/me wonders if find caches results or something to speed it up when you do a similar find afterwards.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Pieter Breed</title>
		<link>http://danielmiessler.com/blog/linux-xargs-vs-exec/comment-page-1#comment-9102</link>
		<dc:creator>Pieter Breed</dc:creator>
		<pubDate>Mon, 30 Oct 2006 19:59:48 +0000</pubDate>
		<guid isPermaLink="false">http://dmiessler.com/archives/986#comment-9102</guid>
		<description>&lt;p&gt;What impant did harddrive caching have on your test?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>What impant did harddrive caching have on your test?</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Rory</title>
		<link>http://danielmiessler.com/blog/linux-xargs-vs-exec/comment-page-1#comment-9099</link>
		<dc:creator>Rory</dc:creator>
		<pubDate>Mon, 30 Oct 2006 17:35:18 +0000</pubDate>
		<guid isPermaLink="false">http://dmiessler.com/archives/986#comment-9099</guid>
		<description>&lt;p&gt;mikkom:
I&#039;m not too familiar with xargs, but I think this find expression will do what you want:&lt;/p&gt;

&lt;p&gt;find . -maxdepth 1 -name &#039;*jpg&#039; -exec convert &#039;{}&#039; -resize 90x -crop 90×90 0 0 &#039;{}&#039; &#039;;&#039;&lt;/p&gt;

&lt;p&gt;I usually put &#039;&#039; around {} in case of spaces.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>mikkom:
I&#8217;m not too familiar with xargs, but I think this find expression will do what you want:</p>

<p>find . -maxdepth 1 -name &#8216;*jpg&#8217; -exec convert &#8216;{}&#8217; -resize 90x -crop 90×90 0 0 &#8216;{}&#8217; &#8216;;&#8217;</p>

<p>I usually put &#8221; around {} in case of spaces.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: mikkom</title>
		<link>http://danielmiessler.com/blog/linux-xargs-vs-exec/comment-page-1#comment-9094</link>
		<dc:creator>mikkom</dc:creator>
		<pubDate>Mon, 30 Oct 2006 16:50:32 +0000</pubDate>
		<guid isPermaLink="false">http://dmiessler.com/archives/986#comment-9094</guid>
		<description>&lt;p&gt;.. and if you are doing a hardcore batch job for 15000 files, are those 6 seconds of shell processing really that important?&lt;/p&gt;

&lt;p&gt;I use xargs but definitely for different reasons than few second difference... I&#039;m not aware if the following example is even possible with -exec:&lt;/p&gt;

&lt;p&gt;ls *jpg&#124;xargs -ifile convert file -resize 90x -crop 90x90 0 0 file&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>.. and if you are doing a hardcore batch job for 15000 files, are those 6 seconds of shell processing really that important?</p>

<p>I use xargs but definitely for different reasons than few second difference&#8230; I&#8217;m not aware if the following example is even possible with -exec:</p>

<p>ls *jpg|xargs -ifile convert file -resize 90x -crop 90&#215;90 0 0 file</p>]]></content:encoded>
	</item>
</channel>
</rss>
