<?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: Harnessing The Über-Powerful Find Command (+xargs)</title>
	<atom:link href="http://danielmiessler.com/blog/linux-harnessing-the-uber-powerful-find-command-xargs/feed" rel="self" type="application/rss+xml" />
	<link>http://danielmiessler.com/blog/linux-harnessing-the-uber-powerful-find-command-xargs</link>
	<description>grep understanding</description>
	<lastBuildDate>Sun, 29 Jan 2012 20:44:46 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Lenny</title>
		<link>http://danielmiessler.com/blog/linux-harnessing-the-uber-powerful-find-command-xargs/comment-page-1#comment-8624</link>
		<dc:creator>Lenny</dc:creator>
		<pubDate>Fri, 13 Oct 2006 02:18:01 +0000</pubDate>
		<guid isPermaLink="false">http://dmiessler.com/archives/955#comment-8624</guid>
		<description>&lt;p&gt;I don&#039;t think the following command-line from your article:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;# Clean the images off of your *nix desktop
find ~/Desktop -name &quot;*.jpg&quot; -o -name &quot;*.gif&quot; -o -name &quot;*.png&quot; -print0 &#124; xargs -0 mv ~/Pictures 
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;will work as you expect. You&#039;ll want to wrap the find(1) -name tests in parentheses, otherwise you&#039;ll only list the *.png files.&lt;/p&gt;

&lt;p&gt;Also, the mv(1) command(s) that xargs(1) will generate, won&#039;t work because 
the last argument needs to be a directory. Assuming your Desktop directory
looks like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ ls Desktop Pictures
Desktop:
bar.png  foo.gif  one.png  three.jpg  two.jpg

Pictures:
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;here&#039;s the results of running your original command-line:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ find Desktop  -name &quot;*.jpg&quot; -o -name &quot;*.gif&quot; -o -name &quot;*.png&quot;  -print0 &#124; xargs -0 -t mv Pictures
mv Pictures Desktop/bar.png Desktop/one.png 
mv: when moving multiple files, last argument must be a directory
Try `mv --help&#039; for more information.
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Here&#039;s a version that will work as you expect:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ find Desktop  \( -name &quot;*.jpg&quot; -o -name &quot;*.gif&quot; -o -name &quot;*.png&quot; \) -print0 &#124; xargs -0 -t mv --target-directory=Pictures
mv --target-directory=Pictures Desktop/three.jpg Desktop/two.jpg Desktop/foo.gif Desktop/bar.png Desktop/one.png

$ ls Desktop Pictures
Desktop:

Pictures:
bar.png  foo.gif  one.png  three.jpg  two.jpg
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;IIRC the --target-directory option is specific to the GNU version of mv(1).&lt;/p&gt;

&lt;p&gt;If you had a standard mv(1) command lacking the --target-directory option, 
you&#039;d need to move one file at a time and xargs wouldn&#039;t provide much benefit
over the -exec feature of find(1):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ find Desktop  \( -name &quot;*.jpg&quot; -o -name &quot;*.gif&quot; -o -name &quot;*.png&quot; \) -print0 &#124;  xargs -0 -t -i mv {} Pictures
mv Desktop/three.jpg Pictures
mv Desktop/two.jpg Pictures
mv Desktop/foo.gif Pictures
mv Desktop/bar.png Pictures
mv Desktop/one.png Pictures

$ ls Desktop Pictures
Desktop:

Pictures:
bar.png  foo.gif  one.png  three.jpg  two.jpg
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The -t option to xargs(1) is your friend. It traces the commands generated
by xargs(1). If you want to be extra cautious, use -p instead and it will 
print each command-line and ask you if you want to proceed.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I don&#8217;t think the following command-line from your article:</p>

<pre><code># Clean the images off of your *nix desktop
find ~/Desktop -name "*.jpg" -o -name "*.gif" -o -name "*.png" -print0 | xargs -0 mv ~/Pictures 
</code></pre>

<p>will work as you expect. You&#8217;ll want to wrap the find(1) -name tests in parentheses, otherwise you&#8217;ll only list the *.png files.</p>

<p>Also, the mv(1) command(s) that xargs(1) will generate, won&#8217;t work because 
the last argument needs to be a directory. Assuming your Desktop directory
looks like this:</p>

<pre><code>$ ls Desktop Pictures
Desktop:
bar.png  foo.gif  one.png  three.jpg  two.jpg

Pictures:
</code></pre>

<p>here&#8217;s the results of running your original command-line:</p>

<pre><code>$ find Desktop  -name "*.jpg" -o -name "*.gif" -o -name "*.png"  -print0 | xargs -0 -t mv Pictures
mv Pictures Desktop/bar.png Desktop/one.png 
mv: when moving multiple files, last argument must be a directory
Try `mv --help' for more information.
</code></pre>

<p>Here&#8217;s a version that will work as you expect:</p>

<pre><code>$ find Desktop  \( -name "*.jpg" -o -name "*.gif" -o -name "*.png" \) -print0 | xargs -0 -t mv --target-directory=Pictures
mv --target-directory=Pictures Desktop/three.jpg Desktop/two.jpg Desktop/foo.gif Desktop/bar.png Desktop/one.png

$ ls Desktop Pictures
Desktop:

Pictures:
bar.png  foo.gif  one.png  three.jpg  two.jpg
</code></pre>

<p>IIRC the &#8211;target-directory option is specific to the GNU version of mv(1).</p>

<p>If you had a standard mv(1) command lacking the &#8211;target-directory option, 
you&#8217;d need to move one file at a time and xargs wouldn&#8217;t provide much benefit
over the -exec feature of find(1):</p>

<pre><code>$ find Desktop  \( -name "*.jpg" -o -name "*.gif" -o -name "*.png" \) -print0 |  xargs -0 -t -i mv {} Pictures
mv Desktop/three.jpg Pictures
mv Desktop/two.jpg Pictures
mv Desktop/foo.gif Pictures
mv Desktop/bar.png Pictures
mv Desktop/one.png Pictures

$ ls Desktop Pictures
Desktop:

Pictures:
bar.png  foo.gif  one.png  three.jpg  two.jpg
</code></pre>

<p>The -t option to xargs(1) is your friend. It traces the commands generated
by xargs(1). If you want to be extra cautious, use -p instead and it will 
print each command-line and ask you if you want to proceed.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Lenny</title>
		<link>http://danielmiessler.com/blog/linux-harnessing-the-uber-powerful-find-command-xargs/comment-page-1#comment-246401</link>
		<dc:creator>Lenny</dc:creator>
		<pubDate>Fri, 13 Oct 2006 02:18:00 +0000</pubDate>
		<guid isPermaLink="false">http://dmiessler.com/archives/955#comment-246401</guid>
		<description>&lt;p&gt;I don&#039;t think the following command-line from your article:&lt;/p&gt;

&lt;p&gt;&lt;pre&gt;&lt;code&gt;# Clean the images off of your &lt;em&gt;nix desktop
find ~/Desktop -name &quot;&lt;/em&gt;.jpg&quot; -o -name &quot;&lt;em&gt;.gif&quot; -o -name &quot;&lt;/em&gt;.png&quot; -print0 &#124; xargs -0 mv ~/Pictures 
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;will work as you expect. You&#039;ll want to wrap the find(1) -name tests in parentheses, otherwise you&#039;ll only list the *.png files.&lt;/p&gt;

&lt;p&gt;Also, the mv(1) command(s) that xargs(1) will generate, won&#039;t work because 
the last argument needs to be a directory. Assuming your Desktop directory
looks like this:&lt;/p&gt;

&lt;p&gt;&lt;pre&gt;&lt;code&gt;$ ls Desktop Pictures
Desktop:
bar.png  foo.gif  one.png  three.jpg  two.jpg&lt;/p&gt;

&lt;p&gt;Pictures:
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;here&#039;s the results of running your original command-line:&lt;/p&gt;

&lt;p&gt;&lt;pre&gt;&lt;code&gt;$ find Desktop  -name &quot;&lt;em&gt;.jpg&quot; -o -name &quot;&lt;/em&gt;.gif&quot; -o -name &quot;*.png&quot;  -print0 &#124; xargs -0 -t mv Pictures
mv Pictures Desktop/bar.png Desktop/one.png 
mv: when moving multiple files, last argument must be a directory
Try `mv --help&#039; for more information.
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;Here&#039;s a version that will work as you expect:&lt;/p&gt;

&lt;p&gt;&lt;pre&gt;&lt;code&gt;$ find Desktop  ( -name &quot;&lt;em&gt;.jpg&quot; -o -name &quot;&lt;/em&gt;.gif&quot; -o -name &quot;*.png&quot; ) -print0 &#124; xargs -0 -t mv --target-directory=Pictures
mv --target-directory=Pictures Desktop/three.jpg Desktop/two.jpg Desktop/foo.gif Desktop/bar.png Desktop/one.png&lt;/p&gt;

&lt;p&gt;$ ls Desktop Pictures
Desktop:&lt;/p&gt;

&lt;p&gt;Pictures:
bar.png  foo.gif  one.png  three.jpg  two.jpg
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;IIRC the --target-directory option is specific to the GNU version of mv(1).&lt;/p&gt;

&lt;p&gt;If you had a standard mv(1) command lacking the --target-directory option, 
you&#039;d need to move one file at a time and xargs wouldn&#039;t provide much benefit
over the -exec feature of find(1):&lt;/p&gt;

&lt;p&gt;&lt;pre&gt;&lt;code&gt;$ find Desktop  ( -name &quot;&lt;em&gt;.jpg&quot; -o -name &quot;&lt;/em&gt;.gif&quot; -o -name &quot;*.png&quot; ) -print0 &#124;  xargs -0 -t -i mv {} Pictures
mv Desktop/three.jpg Pictures
mv Desktop/two.jpg Pictures
mv Desktop/foo.gif Pictures
mv Desktop/bar.png Pictures
mv Desktop/one.png Pictures&lt;/p&gt;

&lt;p&gt;$ ls Desktop Pictures
Desktop:&lt;/p&gt;

&lt;p&gt;Pictures:
bar.png  foo.gif  one.png  three.jpg  two.jpg
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;The -t option to xargs(1) is your friend. It traces the commands generated
by xargs(1). If you want to be extra cautious, use -p instead and it will 
print each command-line and ask you if you want to proceed.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I don&#8217;t think the following command-line from your article:</p>

<p><pre><code># Clean the images off of your <em>nix desktop
find ~/Desktop -name "</em>.jpg" -o -name "<em>.gif" -o -name "</em>.png" -print0 | xargs -0 mv ~/Pictures 
</code></pre></p>

<p>will work as you expect. You&#8217;ll want to wrap the find(1) -name tests in parentheses, otherwise you&#8217;ll only list the *.png files.</p>

<p>Also, the mv(1) command(s) that xargs(1) will generate, won&#8217;t work because 
the last argument needs to be a directory. Assuming your Desktop directory
looks like this:</p>

<p><pre><code>$ ls Desktop Pictures
Desktop:
bar.png  foo.gif  one.png  three.jpg  two.jpg</code></pre></p>

<p>Pictures:
</p>

<p>here&#8217;s the results of running your original command-line:</p>

<p><pre><code>$ find Desktop  -name "<em>.jpg" -o -name "</em>.gif" -o -name "*.png"  -print0 | xargs -0 -t mv Pictures
mv Pictures Desktop/bar.png Desktop/one.png 
mv: when moving multiple files, last argument must be a directory
Try `mv --help' for more information.
</code></pre></p>

<p>Here&#8217;s a version that will work as you expect:</p>

<p><pre><code>$ find Desktop  ( -name "<em>.jpg" -o -name "</em>.gif" -o -name "*.png" ) -print0 | xargs -0 -t mv --target-directory=Pictures
mv --target-directory=Pictures Desktop/three.jpg Desktop/two.jpg Desktop/foo.gif Desktop/bar.png Desktop/one.png</code></pre></p>

<p>$ ls Desktop Pictures
Desktop:</p>

<p>Pictures:
bar.png  foo.gif  one.png  three.jpg  two.jpg
</p>

<p>IIRC the &#8211;target-directory option is specific to the GNU version of mv(1).</p>

<p>If you had a standard mv(1) command lacking the &#8211;target-directory option, 
you&#8217;d need to move one file at a time and xargs wouldn&#8217;t provide much benefit
over the -exec feature of find(1):</p>

<p><pre><code>$ find Desktop  ( -name "<em>.jpg" -o -name "</em>.gif" -o -name "*.png" ) -print0 |  xargs -0 -t -i mv {} Pictures
mv Desktop/three.jpg Pictures
mv Desktop/two.jpg Pictures
mv Desktop/foo.gif Pictures
mv Desktop/bar.png Pictures
mv Desktop/one.png Pictures</code></pre></p>

<p>$ ls Desktop Pictures
Desktop:</p>

<p>Pictures:
bar.png  foo.gif  one.png  three.jpg  two.jpg
</p>

<p>The -t option to xargs(1) is your friend. It traces the commands generated
by xargs(1). If you want to be extra cautious, use -p instead and it will 
print each command-line and ask you if you want to proceed.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Dave</title>
		<link>http://danielmiessler.com/blog/linux-harnessing-the-uber-powerful-find-command-xargs/comment-page-1#comment-8605</link>
		<dc:creator>Dave</dc:creator>
		<pubDate>Wed, 11 Oct 2006 19:29:59 +0000</pubDate>
		<guid isPermaLink="false">http://dmiessler.com/archives/955#comment-8605</guid>
		<description>&lt;p&gt;Excellent stuf!&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Excellent stuf!</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Dave</title>
		<link>http://danielmiessler.com/blog/linux-harnessing-the-uber-powerful-find-command-xargs/comment-page-1#comment-246400</link>
		<dc:creator>Dave</dc:creator>
		<pubDate>Wed, 11 Oct 2006 19:29:00 +0000</pubDate>
		<guid isPermaLink="false">http://dmiessler.com/archives/955#comment-246400</guid>
		<description>&lt;p&gt;Excellent stuf!&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Excellent stuf!</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Miessler</title>
		<link>http://danielmiessler.com/blog/linux-harnessing-the-uber-powerful-find-command-xargs/comment-page-1#comment-8602</link>
		<dc:creator>Daniel Miessler</dc:creator>
		<pubDate>Wed, 11 Oct 2006 15:11:18 +0000</pubDate>
		<guid isPermaLink="false">http://dmiessler.com/archives/955#comment-8602</guid>
		<description>&lt;p&gt;Ah, great comments; thanks!&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Ah, great comments; thanks!</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Miessler</title>
		<link>http://danielmiessler.com/blog/linux-harnessing-the-uber-powerful-find-command-xargs/comment-page-1#comment-246399</link>
		<dc:creator>Daniel Miessler</dc:creator>
		<pubDate>Wed, 11 Oct 2006 15:11:00 +0000</pubDate>
		<guid isPermaLink="false">http://dmiessler.com/archives/955#comment-246399</guid>
		<description>&lt;p&gt;Ah, great comments; thanks!&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Ah, great comments; thanks!</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Artifex</title>
		<link>http://danielmiessler.com/blog/linux-harnessing-the-uber-powerful-find-command-xargs/comment-page-1#comment-8589</link>
		<dc:creator>Artifex</dc:creator>
		<pubDate>Tue, 10 Oct 2006 19:30:19 +0000</pubDate>
		<guid isPermaLink="false">http://dmiessler.com/archives/955#comment-8589</guid>
		<description>&lt;p&gt;It might also be good to mention the standard technique for using find with tar.&lt;/p&gt;

&lt;p&gt;find . -daystart -mtime  0 &gt; temp
tar -cvf stuff.tar -T temp
rm temp&lt;/p&gt;

&lt;p&gt;Generally you don&#039;t want to use xargs with tar and the create (c) flag, unless your sure that there are only a very few files.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>It might also be good to mention the standard technique for using find with tar.</p>

<p>find . -daystart -mtime  0 &gt; temp
tar -cvf stuff.tar -T temp
rm temp</p>

<p>Generally you don&#8217;t want to use xargs with tar and the create (c) flag, unless your sure that there are only a very few files.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Artifex</title>
		<link>http://danielmiessler.com/blog/linux-harnessing-the-uber-powerful-find-command-xargs/comment-page-1#comment-246398</link>
		<dc:creator>Artifex</dc:creator>
		<pubDate>Tue, 10 Oct 2006 19:30:00 +0000</pubDate>
		<guid isPermaLink="false">http://dmiessler.com/archives/955#comment-246398</guid>
		<description>&lt;p&gt;It might also be good to mention the standard technique for using find with tar.&lt;/p&gt;

&lt;p&gt;find . -daystart -mtime  0 &gt; temp
tar -cvf stuff.tar -T temp
rm temp&lt;/p&gt;

&lt;p&gt;Generally you don&#039;t want to use xargs with tar and the create (c) flag, unless your sure that there are only a very few files.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>It might also be good to mention the standard technique for using find with tar.</p>

<p>find . -daystart -mtime  0 &gt; temp
tar -cvf stuff.tar -T temp
rm temp</p>

<p>Generally you don&#8217;t want to use xargs with tar and the create (c) flag, unless your sure that there are only a very few files.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Name Required</title>
		<link>http://danielmiessler.com/blog/linux-harnessing-the-uber-powerful-find-command-xargs/comment-page-1#comment-8588</link>
		<dc:creator>Name Required</dc:creator>
		<pubDate>Tue, 10 Oct 2006 18:20:32 +0000</pubDate>
		<guid isPermaLink="false">http://dmiessler.com/archives/955#comment-8588</guid>
		<description>&lt;p&gt;you should mention how to redirect the permission denied messages&lt;/p&gt;

&lt;p&gt;find / -name required 2&gt; /dev/null&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>you should mention how to redirect the permission denied messages</p>

<p>find / -name required 2&gt; /dev/null</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Name Required</title>
		<link>http://danielmiessler.com/blog/linux-harnessing-the-uber-powerful-find-command-xargs/comment-page-1#comment-246397</link>
		<dc:creator>Name Required</dc:creator>
		<pubDate>Tue, 10 Oct 2006 18:20:00 +0000</pubDate>
		<guid isPermaLink="false">http://dmiessler.com/archives/955#comment-246397</guid>
		<description>&lt;p&gt;you should mention how to redirect the permission denied messages&lt;/p&gt;

&lt;p&gt;find / -name required 2&gt; /dev/null&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>you should mention how to redirect the permission denied messages</p>

<p>find / -name required 2&gt; /dev/null</p>]]></content:encoded>
	</item>
</channel>
</rss>

