<?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>kyleabaker.com &#187; find</title> <atom:link href="http://kyleabaker.com/tag/find/feed/" rel="self" type="application/rss+xml" /><link>http://kyleabaker.com</link> <description>Web Technologies, Linux, Tips, Tricks and my Life</description> <lastBuildDate>Mon, 09 Jan 2012 03:53:06 +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>Linux: Find and remove matching files</title><link>http://kyleabaker.com/2008/10/19/linux-find-and-remove-matching-files/</link> <comments>http://kyleabaker.com/2008/10/19/linux-find-and-remove-matching-files/#comments</comments> <pubDate>Mon, 20 Oct 2008 02:41:37 +0000</pubDate> <dc:creator>kyleabaker</dc:creator> <category><![CDATA[Linux]]></category> <category><![CDATA[find]]></category> <category><![CDATA[remove]]></category> <category><![CDATA[xargs]]></category> <guid
isPermaLink="false">http://kyleabaker.com/?p=2080</guid> <description><![CDATA[I frequently use find to find all files matching a pattern and then delete them. I catch myself searching for the proper syntax to using this so I&#8217;m now going to blog it so I can find it easily from now on. Lots of times I will use this technique to remove all &#8220;Thumbs.db&#8221; files [...]]]></description> <content:encoded><![CDATA[<p>I frequently use find to find all files matching a pattern and then delete them. I catch myself searching for the proper syntax to using this so I&#8217;m now going to blog it so I can find it easily from now on.</p><p>Lots of times I will use this technique to remove all &#8220;Thumbs.db&#8221; files from an NTFS, you know&#8230;the little database files that Windows XP by default automatically creates in every single folder that contains an image. They annoy me, so I use methods like the ones listed below to remove them.</p><p>If you want to use this, if will find all matching instances from the directory that you are in and following sub-directories. It will not search in parent directories.</p><p>The examples below will search for all Debian packages. Examples: this.deb, that.deb, those.deb, etc. Notice that the * is a wild card expression.</p><p>One simple way of doing this is:</p><blockquote><p><span
style="color: #808080;">username@host:~$</span> <span
style="color: #800000;">find . -name &#8216;*.deb&#8217; -exec rm -f \{\} \;</span></p></blockquote><p>The most common way of doing this is to use xargs, such that you don&#8217;t spawn one command for each file to be deleted:</p><blockquote><p><span
style="color: #808080;">username@host:~$ </span><span
style="color: #800000;">find . -name &#8220;*.deb&#8221; -print | xargs rm</span></p></blockquote><p><em>(Note: Yes I&#8217;m ignoring files with spaces in their names.)</em></p><p>Here is another method that I found online that seems to be less common, but it makes the most sense of all three:</p><blockquote><p><span
style="color: #808080;">username@host:~$ </span><span
style="color: #800000;">find . -name &#8220;*.deb&#8221; -delete</span></p></blockquote><p>You can also just use the following method to list the files in the terminal to make sure that the results are correct and to make sure that you want to delete them before you accidentally delete the wrong ones. <img
src='http://kyleabaker.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p><blockquote><p><span
style="color: #808080;">username@host:~$ </span><span
style="color: #800000;">find . -name &#8220;*.deb&#8221; -print</span></p></blockquote><p>If the results are too long to fit in the terminal or you&#8217;d just like to have them in a text file then you can send the output to a text file instead by appending the following to the end of any command in the terminal.</p><blockquote><p><span
style="color: #800000;">&gt; output.txt</span><br
/> <em>(Here is an example)</em><br
/> <span
style="color: #808080;">username@host:~$ </span><span
style="color: #800000;">find . -name &#8220;*.deb&#8221; -print &gt; output.txt</span></p></blockquote><p>If you know of any other methods, please feel free to share them!</p> ]]></content:encoded> <wfw:commentRss>http://kyleabaker.com/2008/10/19/linux-find-and-remove-matching-files/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> </channel> </rss>
