<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>danielmiessler.com - Latest Comments in Linux: Harnessing The Über-Powerful Find Command (+xargs)</title><link>http://drm.disqus.com/</link><description>https://danielmiessler.com/about/</description><atom:link href="https://drm.disqus.com/linux_harnessing_the_uber_powerful_find_command_xargs/latest.rss" rel="self"></atom:link><language>en</language><lastBuildDate>Thu, 12 Oct 2006 22:18:01 -0000</lastBuildDate><item><title>Re: Linux: Harnessing The Über-Powerful Find Command (+xargs)</title><link>http://https://danielmiessler.com/blog/linux-harnessing-the-uber-powerful-find-command-xargs#comment-11151057</link><description>&lt;p&gt;I don't think the following command-line from your article:&lt;/p&gt;&lt;p&gt;    # Clean the images off of your *nix desktop&lt;br&gt;    find ~/Desktop -name "*.jpg" -o -name "*.gif" -o -name "*.png" -print0 | xargs -0 mv ~/Pictures&lt;/p&gt;&lt;p&gt;will work as you expect. You'll want to wrap the find(1) -name tests in parentheses, otherwise you'll only list the *.png files.&lt;/p&gt;&lt;p&gt;Also, the mv(1) command(s) that xargs(1) will generate, won't work because &lt;br&gt;the last argument needs to be a directory. Assuming your Desktop directory&lt;br&gt;looks like this:&lt;/p&gt;&lt;p&gt;    $ ls Desktop Pictures&lt;br&gt;    Desktop:&lt;br&gt;    bar.png  foo.gif  one.png  three.jpg  two.jpg&lt;/p&gt;&lt;p&gt;    Pictures:&lt;/p&gt;&lt;p&gt;here's the results of running your original command-line:&lt;/p&gt;&lt;p&gt;    $ find Desktop  -name "*.jpg" -o -name "*.gif" -o -name "*.png"  -print0 | xargs -0 -t mv Pictures&lt;br&gt;    mv Pictures Desktop/bar.png Desktop/one.png &lt;br&gt;    mv: when moving multiple files, last argument must be a directory&lt;br&gt;    Try `mv --help' for more information.&lt;/p&gt;&lt;p&gt;Here's a version that will work as you expect:&lt;/p&gt;&lt;p&gt;    $ find Desktop  \( -name "*.jpg" -o -name "*.gif" -o -name "*.png" \) -print0 | xargs -0 -t mv --target-directory=Pictures&lt;br&gt;    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&lt;br&gt;    Desktop:&lt;/p&gt;&lt;p&gt;    Pictures:&lt;br&gt;    bar.png  foo.gif  one.png  three.jpg  two.jpg&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, &lt;br&gt;you'd need to move one file at a time and xargs wouldn't provide much benefit&lt;br&gt;over the -exec feature of find(1):&lt;/p&gt;&lt;p&gt;    $ find Desktop  \( -name "*.jpg" -o -name "*.gif" -o -name "*.png" \) -print0 |  xargs -0 -t -i mv {} Pictures&lt;br&gt;    mv Desktop/three.jpg Pictures&lt;br&gt;    mv Desktop/two.jpg Pictures&lt;br&gt;    mv Desktop/foo.gif Pictures&lt;br&gt;    mv Desktop/bar.png Pictures&lt;br&gt;    mv Desktop/one.png Pictures&lt;/p&gt;&lt;p&gt;    $ ls Desktop Pictures&lt;br&gt;    Desktop:&lt;/p&gt;&lt;p&gt;    Pictures:&lt;br&gt;    bar.png  foo.gif  one.png  three.jpg  two.jpg&lt;/p&gt;&lt;p&gt;The -t option to xargs(1) is your friend. It traces the commands generated&lt;br&gt;by xargs(1). If you want to be extra cautious, use -p instead and it will &lt;br&gt;print each command-line and ask you if you want to proceed.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Lenny</dc:creator><pubDate>Thu, 12 Oct 2006 22:18:01 -0000</pubDate></item><item><title>Re: Linux: Harnessing The Über-Powerful Find Command (+xargs)</title><link>http://https://danielmiessler.com/blog/linux-harnessing-the-uber-powerful-find-command-xargs#comment-11151055</link><description>&lt;p&gt;Excellent stuf!&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Dave</dc:creator><pubDate>Wed, 11 Oct 2006 15:29:59 -0000</pubDate></item><item><title>Re: Linux: Harnessing The Über-Powerful Find Command (+xargs)</title><link>http://https://danielmiessler.com/blog/linux-harnessing-the-uber-powerful-find-command-xargs#comment-11151053</link><description>&lt;p&gt;Ah, great comments; thanks!&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Daniel Miessler</dc:creator><pubDate>Wed, 11 Oct 2006 11:11:18 -0000</pubDate></item><item><title>Re: Linux: Harnessing The Über-Powerful Find Command (+xargs)</title><link>http://https://danielmiessler.com/blog/linux-harnessing-the-uber-powerful-find-command-xargs#comment-11151052</link><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 &amp;gt; temp&lt;br&gt;tar -cvf stuff.tar -T temp&lt;br&gt;rm temp&lt;/p&gt;&lt;p&gt;Generally you don'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><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Artifex</dc:creator><pubDate>Tue, 10 Oct 2006 15:30:19 -0000</pubDate></item><item><title>Re: Linux: Harnessing The Über-Powerful Find Command (+xargs)</title><link>http://https://danielmiessler.com/blog/linux-harnessing-the-uber-powerful-find-command-xargs#comment-11151050</link><description>&lt;p&gt;you should mention how to redirect the permission denied messages&lt;/p&gt;&lt;p&gt;find / -name required 2&amp;gt; /dev/null&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Name Required</dc:creator><pubDate>Tue, 10 Oct 2006 14:20:32 -0000</pubDate></item></channel></rss>