<?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>I Can Has Linux? &#187; findutils</title>
	<atom:link href="http://icanhaslinux.com/category/findutils/feed/" rel="self" type="application/rss+xml" />
	<link>http://icanhaslinux.com</link>
	<description>Invisible Patent Infringement!</description>
	<lastBuildDate>Mon, 29 Aug 2011 13:37:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>8 Steps to Becoming A `find` Fu Master &#8212; Pt 2</title>
		<link>http://icanhaslinux.com/2009/02/06/8-steps-to-becoming-a-find-fu-master-pt-2/</link>
		<comments>http://icanhaslinux.com/2009/02/06/8-steps-to-becoming-a-find-fu-master-pt-2/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 16:35:06 +0000</pubDate>
		<dc:creator>LightningCrash</dc:creator>
				<category><![CDATA[find]]></category>
		<category><![CDATA[findutils]]></category>
		<category><![CDATA[gnu]]></category>

		<guid isPermaLink="false">http://icanhaslinux.com/2009/02/06/8-steps-to-becoming-a-find-fu-master-pt-2/</guid>
		<description><![CDATA[(This is the second part in a three part series. Review the Introduction Here) Now for the second installment of your `find` fu mastery! We are going to cover four principles today: Learning to use object types Using command execution Using `find` to delete files Limiting search depth With no further ado, 1. Using object [...]]]></description>
			<content:encoded><![CDATA[<p><em>(This is the second part in a three part series. <a href="http://icanhaslinux.com/2009/02/05/8-steps-to-becoming-a-find-fu-master-introduction/">Review the Introduction Here</a>)</em></p>
<p>Now for the second installment of your `find` fu mastery! We are going to cover four principles today:</p>
<ol>
<li>Learning to use object types</li>
<li> Using command execution</li>
<li>Using `find` to delete files</li>
<li>Limiting search depth</li>
</ol>
<p>With no further ado,</p>
<p><strong>1. Using object types in `find`</strong></p>
<p>In the Linux/Unix filesystems there are more things than plain old regular files. Among then are symbolic links, directories, named pipes, block devices, character devices, and sockets. `find` will let you specify these items.</p>
<p>For instance, if I am looking for the baseq3 directory of my Quake3 installation, I can do the following:</p>
<p><code>find / -type d -name 'baseq3'</code></p>
<p>If I am looking for all symbolic links in a directory, I can do the following:</p>
<p><code>find . -type l</code></p>
<p>If I am looking for only files, I can specify &#8216;-type f&#8217;. This is handy by itself, but becomes more useful as you are executing commands for each of your search results. Which brings us to&#8230;</p>
<p><strong>2. Using Command Execution</strong></p>
<p>This is probably one of the most useful things that `find` has to offer. This is also one of the easiest ways to screw up your system and/or your day&#8217;s work. You have to be careful with this. Fortunately, `find` puts options in to help with that. We&#8217;ll cover those in a moment after we give some basics of command execution in `find`.</p>
<p>I have a directory full of PHP source code and I want to issue a find/replace on every file in the entire hierarchy to change a setting. The setting&#8217;s value is 12345 and I want to change it to 67890. You use the -exec option , put your command in, substitute the filename with {}, and put \; to denote the end of the command. Let&#8217;s take a look:</p>
<p><code>find ./ -type f -exec perl -pi -e 's/12345/67890/g' {} \;</code></p>
<p>This works great, except how do I know I&#8217;m not executing something that I don&#8217;t want to? Well,`find` has this covered with the &#8216;ok&#8217; option.</p>
<p><code>find ./ -type f -ok perl -pi -e 's/12345/67890/g' {} \;</code></p>
<p>This will now prompt you to OK everything that is done, line by line. Useful for if you&#8217;re going to do something where you&#8217;d like to know which files it&#8217;s operating on. However, `find` will truncate part of the command if it&#8217;s too long, so you don&#8217;t get to see exactly what it&#8217;s doing. You can always put an echo in front of your commands to see them in their entirety before you execute them.</p>
<p>`find` also has an -execdir and -okdir command, which operate in a different manner. -execdir operates as if you `cd` into the directory and then run the command. This can be handy if you don&#8217;t want to do the filename substitution with {}, maybe you want to run something inside every directory. If you have a directory full of source called src, and maybe you want to run the `make` command to compile everything, you could issue a `find` statement like so:</p>
<p><code>find ./src -type d -execdir make all \;</code></p>
<p>This is a bit messy but it illustrates my point.</p>
<p><strong> 3. Using `find` to delete files</strong></p>
<p>Speaking of dangerous operations, here&#8217;s another one you need to be very, very careful with.</p>
<p>But the easiest way to illustrate this would be to say maybe you downloaded a package for installation that contained a number of files that you do not want at all. Some shared packages come with .nfo files, .txt, .installs, .sfx, .subs, all sorts of unwanted garbage that you rarely want. Let&#8217;s allow `find` to delete that garbage, shall we?</p>
<p>I&#8217;m going to make these .sfx files disappear&#8230;</p>
<p><code>cd ~/Downloads/package/<br />
</code></p>
<p><code> find ./ -type f -name '*.sfx' -delete</code></p>
<p>Ta-da!</p>
<p>:jokerface:</p>
<p><strong>4. Limiting Search Depth</strong></p>
<p>So maybe you want to only go one directory deep. Maybe you don&#8217;t want to descend into any directories with your search. Maybe you want to search a filesystem without having `find` hop onto other drives in its search. `find` has got you covered like a fire team.</p>
<p>Descend only one directory:</p>
<p><code>find ./ -maxdepth 1</code></p>
<p>Don&#8217;t descend at all:</p>
<p><code>find ./ -maxdepth 0</code></p>
<p>Don&#8217;t search on filesystems or drives other than the current one:</p>
<p><code>find ./ -xdev</code></p>
<p>The above is particularly useful if you have a jump drive of some sort mounting in an inappropriate place.</p>
<p><strong>Wrapping up</strong>.</p>
<p>Can you snatch the pebble from your filesystem&#8217;s hand?</p>
<p>We train again later, grasshopper.</p>
<p>-LightningCrash</p>
]]></content:encoded>
			<wfw:commentRss>http://icanhaslinux.com/2009/02/06/8-steps-to-becoming-a-find-fu-master-pt-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>8 Steps to Becoming A `find` Fu Master &#8212; Introduction</title>
		<link>http://icanhaslinux.com/2009/02/05/8-steps-to-becoming-a-find-fu-master-introduction/</link>
		<comments>http://icanhaslinux.com/2009/02/05/8-steps-to-becoming-a-find-fu-master-introduction/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 13:52:51 +0000</pubDate>
		<dc:creator>LightningCrash</dc:creator>
				<category><![CDATA[find]]></category>
		<category><![CDATA[findutils]]></category>
		<category><![CDATA[gnu]]></category>

		<guid isPermaLink="false">http://icanhaslinux.com/2009/02/05/8-steps-to-becoming-a-find-fu-master-introduction/</guid>
		<description><![CDATA[(This is the first part in a three part series. Read part two here.) Introduction: Among the tools you will use on a Linux system, few are more valuable than the find utility from findutils. Forget search bars: This is a more highly tailored search system that can help you find exactly what you&#8217;re looking [...]]]></description>
			<content:encoded><![CDATA[<p><em>(This is the first part in a three part series. Read <a href="http://icanhaslinux.com/2009/02/06/8-steps-to-becoming-a-find-fu-master-pt-2/">part two here.</a>)</em></p>
<p><strong>Introduction:</strong></p>
<p>Among the tools you will use on a Linux system, few are more valuable than the find utility from findutils. Forget search bars: This is a more highly tailored search system that can help you find exactly what you&#8217;re looking for with great ease. It will also permit you to perform operations upon the files that you find, delete them, or just list them. If you do more than just browse the Internet with your Linux box, you need some sort of proficiency with find.</p>
<p><strong>Basics:</strong><br />
Find, at its simplest, will list everything in the filesystem beneath your current directory. This includes files, directories, symbolic links, FIFOs, sockets, and more other crap than you probably care to know about. Over 95% of your usage is going to be finding files and directories, so we&#8217;ll focus there.<br />
If you open up a terminal and type<br />
<code>cd<br />
find</code><br />
You&#8217;ll receive a list of everything in the filesystem below your current directory.<br />
Let&#8217;s limit that some. Let&#8217;s search for files that end in mp3.<br />
<code>find -name '*.mp3'</code></p>
<p>But wait, I know I had a file that ended in .MP3, why didn&#8217;t it show up? Well, the -name test is case sensitive. -iname is not. Let&#8217;s do the same thing with iname.</p>
<p><code>find -iname '*.mp3'</code></p>
<p>Ahh, there it is.<br />
I want to search my videos directory for the video of my friend&#8217;s birthday party. I know it was named Fred-something. Now I can introduce a directory in the search.</p>
<p><code>find ~/Videos/ -name '*Fred*'</code></p>
<p>Hah. Fred is silly.</p>
<p>Well, that&#8217;s the most basic that you&#8217;ll get with find, grasshopper. Now you must prove your skills to the sensei!</p>
<p>Well, sort of. You just have to wait for the next part of the series.</p>
<p>-LightningCrash</p>
<p><em>(This is the first part in a three part series. Read <a href="http://icanhaslinux.com/2009/02/06/8-steps-to-becoming-a-find-fu-master-pt-2/">part two here.</a>)</em></p>
]]></content:encoded>
			<wfw:commentRss>http://icanhaslinux.com/2009/02/05/8-steps-to-becoming-a-find-fu-master-introduction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>De-RIAAing my music collection</title>
		<link>http://icanhaslinux.com/2007/10/05/de-riaaing-my-music-collection/</link>
		<comments>http://icanhaslinux.com/2007/10/05/de-riaaing-my-music-collection/#comments</comments>
		<pubDate>Fri, 05 Oct 2007 15:34:00 +0000</pubDate>
		<dc:creator>LightningCrash</dc:creator>
				<category><![CDATA[awk]]></category>
		<category><![CDATA[findutils]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[music]]></category>
		<category><![CDATA[riaa]]></category>
		<category><![CDATA[sed]]></category>
		<category><![CDATA[xargs]]></category>

		<guid isPermaLink="false">http://icanhaslinux.com/2007/10/05/de-riaaing-my-music-collection/</guid>
		<description><![CDATA[I recently decided that I won&#8217;t own any music from an artist that is represented by the RIAA. Now, how do I go about De-RIAAing my ripped albums? RIAA Radar has a website that will let you search for artists, albums, keywords, etc and it will give you information as to whether or not an [...]]]></description>
			<content:encoded><![CDATA[<p align="left">I recently decided that I won&#8217;t own any music from an artist that is represented by the RIAA. Now, how do I go about De-RIAAing my ripped albums?</p>
<p align="left"><a href="http://www.riaaradar.com/">RIAA Radar</a> has a website that will let you search for artists, albums, keywords, etc and it will give you information as to whether or not an album was released under the RIAA.</p>
<p align="left">So I did a view-source on their search page and determined that there are only three variables that you need to POST in order to search: searchtype, keyword, and submit.</p>
<p align="left">I can use wget to grab the file, like so:<br />
<code>wget http://www.riaaradar.com/search.asp --post-data "searchtype=ArtistSearch&amp;keyword=Audioslave&amp;submit=Go\!" -O Audioslave</code></p>
<p align="left">This saves the file as Audioslave. Audioslave IS represented by the RIAA, by the way.</p>
<p align="left">Now, how do I take my ripped albums and compare them to the RIAA Radar site?</p>
<p align="left"><span id="more-59"></span><br />
In my album collection, all of the albums are formatted the same: Artist &#8211; Album Name<br />
This little bit of effort a long time ago makes it easy for me to separate these now.<br />
I simply cd into my albums directory and do the following:<br />
<code>ls|awk '{FS="-"};{ print $1}'|uniq &gt;&gt; artists</code></p>
<p align="left">I now have a file called artists in my album collection that contains unique artist names for every album in the collection.</p>
<p align="left">Now, to find out if they&#8217;re represented by the RIAA:</p>
<p align="left"><code>cat artists|tr " " "+"|xargs -i wget http://www.riaaradar.com/search.asp --post-data "searchtype=ArtistSearch&amp;keyword={}&amp;submit=Go\!" -O radarresults{}.html</code></p>
<p align="left">This will pull down the search result for every artist in my album list, and save it in a file formatted the way I want.<br />
For instance, Jimi Hendrix would be saved as radarresultsJimi+Hendrix.html</p>
<p align="left">I browse this with lynx and see that the text &#8220;Warning!&#8221; would be pretty good to search on.</p>
<p align="left"><code>grep Warning! radarresults*|sed -e 's/&lt;[^&lt;&gt;]*&gt;//g'|tr "+" " "|cut -c 13-|uniq|awk '{FS=".html"};{print $1}' &gt;&gt; riaapunks.txt</code></p>
<p align="left">Explanation: grep searches the files for Warning!, then sed strips out the html. tr converts those + signs to spaces, cut trims off the radarresults portion of the output, uniq filters out duplicates, awk cuts off everything after and including .html, then it all gets dumped to a file.</p>
<p align="left">Now I&#8217;ve got a nice list of everyone who is represented by the RIAA, in a file called riaapunks.txt</p>
<p align="left">Now I get to have fun with it!<br />
<code>cat riaapunks.txt|xargs --verbose -i find ./ -name *{}* </code></p>
<p align="left">Output looks good. Now for the coup de grace:<br />
<code>cat riaapunks.txt|xargs --verbose -i find ./ -name *{}* -delete</code></p>
<p align="left">Buh-bye RIAA music!</p>
]]></content:encoded>
			<wfw:commentRss>http://icanhaslinux.com/2007/10/05/de-riaaing-my-music-collection/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

